Convert string to datetime
I am trying to convert a date string from one format to another. However, I am getting this exception error
The string was not recognized as a valid DateTime.
My code looks like this:
string theDate = "28-Feb-13 4:00:00 PM";
DateTime tempDate = DateTime.ParseExact(theDate, "dd-MMM-yy hh:mm:ss tt", CultureInfo.InvariantCulture, DateTimeStyles.None);
convertedDate = tempDate.ToString("yyyy/MM/dd hh:mm:ss");
I seriously don't know what went wrong.
+3
source to share