Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please help me

I have time in database table as

10/15/2012 02:07:42 PM

I have Retreieved using label is displaying what ever it is in database.

I need to display as 15/10/2012 02:07:42 pm using label. DD/MM/YYYY and time.

Please help me, am trying a lot .

Thanks for ever.
Posted
Comments
I.explore.code 15-Oct-12 6:29am    
Just use a custom format string!
Aarti Meswania 15-Oct-12 6:42am    
you have re-post question where you stuck, do you get error or anything else like page is refreshed and output is not displayed in control?

Once you retrieve it use following code

C#
string yourDate = "10/15/2012 02:07:42 PM";
DateTime datetime = DateTime.ParseExact(yourDate, "MM/dd/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture);

string formattedDate = datetime.ToString("dd/MM/yyyy hh:mm:ss tt");


Dont forget to add using System.Globalization namespace!

Hope that helps. If it does, mark it as answer/upvote.
Thanks
Milind
 
Share this answer
 
if in database your date column's datatype is DateTime then,

use below line for output in C#,
C#
label1.Text = dt.Rows[0]["YourDateFieldNameFromDB"].Value.ToString("dd/MM/yyyy hh:mm tt");

Happy Coding!
:)

[Aman.A]corrected the format string typo[/Aman.A]
 
Share this answer
 
v3
Comments
I.explore.code 15-Oct-12 6:32am    
A correction there (i m sure its just a typo): the format string should be "dd/MM/yyyy hh:mm tt". "MM" would display the month. :) FTFY.
Aarti Meswania 15-Oct-12 6:33am    
oh yes!, thanks :)
I.explore.code 15-Oct-12 6:37am    
Pleasure!
Use below Code

C#
label1.Text = DateTime.Value.ToString("dd/MM/yyyy hh:MM tt");

Refer below link
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900