Click here to Skip to main content
15,911,141 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
See more:
How to parse SQL datetime in c#.

in Database its like this "2003-12-31 00:00:00"
i want like this "12/31/2003 12:00:00 AM"

please help...
Posted
Comments
Sergey Alexandrovich Kryukov 29-May-15 2:06am    
You should not use strings where the time types are needed. Then you won't need to parse anything.
—SA
Member 8222588 29-May-15 2:09am    
i use double quote to show date only here. in code its not a string
Saroj Kumar Sahu 29-May-15 2:14am    
please mention the required Output format type also means is it in string or datetime ?
Member 8222588 29-May-15 2:17am    
datetime

Dates in a database aren't stored with any format, unless they are stored as strings - which you say you aren't doing. Instead, they are stored as a number of microseconds since an arbitrary point in time.

They only acquire a format when you convert them to a string for presentation - which would normally be done in presentation software rather than in SQL so that it is in the format preferred by the user.
But you can select the format for the string in SQL:w3Schools[^]
 
Share this answer
 
 
Share this answer
 
string date = "2003-12-31 00:00:00";
string [] Arr=Convert.ToDateTime(date).GetDateTimeFormats();
Console.WriteLine(Arr[71]);
Console.ReadLine();
 
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