Click here to Skip to main content
15,889,867 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone,

I have developing a project with asp .net (c#) and i have problem with the date-time objects.
I have many records in ms-sql with dates, i am trying show that dates in a web page in this 24-hour format (not AM or PM). But i cannot do that.
I was change server's regional options to 24-hour format but it did not work.

Is there a way to change this format in a code(c#) side ?

Thanks,
Posted
Comments
Toniyo Jackson 7-Sep-11 6:28am    
Show your code?

Use DateTime.ToString[^]
like, yourDate.ToString("dd/MM/yyyy HH:mm:ss") (HH for 24 hours | hh for 12 hours)
 
Share this answer
 
Comments
hilmisu 7-Sep-11 6:47am    
Thanks !! i can't believe that i missed that =)
Prerak Patel 7-Sep-11 7:14am    
You are welcome.
Don't touch your servers options: you want to display the date/time in the Clients preferred format if at all possible.
MSDN can help there: http://msdn.microsoft.com/en-us/library/bb882561.aspx[^]

Or you can use DateTime.ToString as previously suggested - there is a list of all the available format codes here: Formatting a DateTime for display - format string description[^]
 
Share this answer
 
Ofcourse, here is example.
DateTime dt = System.DateTime.Now;
string strDate = dt.ToString("Date_Format_of_your_choice");
 
Share this answer
 
Comments
hilmisu 7-Sep-11 6:32am    
Actually i tried this,
string strDate = dt.ToString("yyyy-MM-dd 00:00");
It kind of work but, it shows the hour 08:00 if the morning, if it's evening again it shows the hour 08:00. This is not work for me, thanks.
nagendrathecoder 7-Sep-11 6:36am    
You have to use "yyyy-MM-dd HH:mm" format.
HH gives 24 hour pattern whereas hh gives 12 hour pattern.
Try it.

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