ixora
ixora

Reputation: 185

Convert string to datetime issue

I'm trying to convert a date string in one format into another. However, I get this exception error message

String was not recognized as a valid DateTime.

My code is as follows:

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 have no idea what went wrong.

Upvotes: 2

Views: 281

Answers (1)

Farhad Jabiyev
Farhad Jabiyev

Reputation: 26665

You must change

28-Feb-13 4:00:00 PM to 28-Feb-13 04:00:00 PM

or

dd-MMM-yy hh:mm:ss tt to dd-MMM-yy h:mm:ss tt

Upvotes: 13

Related Questions