Question : Converting datetime of the format MM/dd/yyyy HH:mm:ss.fff to yyyy-MM-dd HH:mm:ss.fff  in asp.net C#

Hi!

I have a drop down list with  a list of dates in the format  MM/dd/yyyy HH:mm:ss.fff . when I select a date from the dropdown list, it needs to be sent to thae database
and retrieve the information. In the table, the date is of the format  yyyy-MM-dd HH:mm:ss.fff

when the send the value as DateTime.Parse(ddl.selected value.ToString()),

it's not converting the date to the appropriate format.

Please let me know, how can I get the desired format.
Thanks a lot in advance!

Answer : Converting datetime of the format MM/dd/yyyy HH:mm:ss.fff to yyyy-MM-dd HH:mm:ss.fff  in asp.net C#

Datetime currentTime = DateTime.Now;

string currentTimeAsString = currentTime.ToString("yyyy-MM-dd HH:mm:ss.fff");

There is no formatting like that for dates in MS SQL Server. There is a limited one which is this:
http://www.blackwasp.co.uk/SQLDateTimeFormats.aspx

If this does not answer your question, please let me know what you would like to do exactly.
Random Solutions  
 
programming4us programming4us