Martijn
Martijn

Reputation: 392

Cant parse string to datetime

DateTime startDate = DateTime.ParseExact("2011-05-25 24:00:00", "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);

for some reason parsing this string to a datetime does not want to work. I Tried several things already but it just does not want to work. Most of the internet examples do it like this too. Does someone sees what is wrong?

thanks

Upvotes: 1

Views: 965

Answers (1)

Fredrik Mörk
Fredrik Mörk

Reputation: 158289

"24:00:00" is not a valid time. Should probably be "00:00:00". If you meant the second that comes after 2011-05-25 23:59:59, that would be 2011-05-26 00:00:00.

For more information about valid value ranges for different format specifiers, check Custom Date and Time Format Strings at MSDN.

Upvotes: 6

Related Questions