Reputation: 3345
I am trying to convert a datetime in the following format;
Mar 30 19:34:33 2013
to a set format I defined. Despite using the correct syntax it fails to convert giving an error:
String was not recognized as a valid DateTime.
Here is the code:
Dim theDate As DateTime = DateTime.ParseExact(contentDate, "MMM dd HH:mm:ss yyyy", CultureInfo.InvariantCulture)
newDate = theDate.ToString("yyyy-MM-dd HH:mm:ss")
Is there something I am doing wrong here.
Upvotes: 0
Views: 127
Reputation: 25013
You have two spaces before the year but only one in the format string. You could use
Dim theDate As DateTime = DateTime.ParseExact(contentDate, "MMM dd HH:mm:ss yyyy", Globalization.CultureInfo.InvariantCulture, Globalization.DateTimeStyles.AllowWhiteSpaces)
Upvotes: 4