I have a string stored in table "13/12/1985 12:00:00 a.m."
when i tried to convert this to Datetime, i am getting an exception saying "String is not a valid DateTime Format". It is because the first part of the string(13)
is month. Is there any way to convert the above string to (mm/dd/yyyy hh:mm:ss am/pm
) format?. Actually the string saved in table is in the format of "dd/mm/yyyy". I want to convert to "mm/dd/yyyy" in Datetime
Try this, its convert dd/MM/yyyy hh:mm:ss tt
format datetime to MM/dd/yyyy hh:mm:ss tt
format
DateTime dt = DateTime.ParseExact("26/04/2016 12:00:00 PM", "dd/MM/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture);
string newdate = dt.ToString("MM/dd/yyyy hh:mm:ss tt")