Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I store date in database using Date Time.Now function. The date is stored in database like(ex 2014-03-28 18:39:18.250). when i fetch this time using query then the time is converted means show 6:39:18.250 . I want the time in correct format means (18:39:18.250)
Posted

Visit: Hopefully one of them may be useful

http://www.csharp-examples.net/string-format-datetime/[^]
 
Share this answer
 
Try this
DateTime nowTime = DataContext.GetServerDate();
 
Share this answer
 
Basically you answered it yourself!
string type has many formatting options (standard and custom)!
C#
DateTime yourDate;

//... getting dateTime value

string formattedTime = yourDate.ToString("hh:mm:ss");
 
Share this answer
 
Assuming datavalue is the date value that you retrieved from database, in the code behind:
string format = "yyyy-MM-dd HH:mm:ss:fff"; 
Console.WriteLine(datavalue.ToString(format)); 
 
Share this answer
 
have a try of this

as you can see the shortFormat will return the following format hh:MM and the long will return hh:MM:ss

C#
DateTime date = DateTime.Now;
string shortFOrmat = date.ToShortTimeString();
string LongFormat = date.ToLongTimeString();
 
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