string not recognized as valid dateTime, when it appears?

I'm getting the error "String was not recognized as a valid DateTime."

When I debug through the code at the line:

DateTime targetDate = DateTime.ParseExact(TargetDate, "yyyy-MM-dd", new CultureInfo("en-GB"));

Holding the cursor over TargetDate displays today's date 'Thu 19 December'.

Any ideas as to what is wrong?

Jon Skeet
people
quotationmark

Holding the cursor over 'TargetDate' displays todays date 'Thu 19 December'

Well that explains it.

The string "Thu 19 December" is not in the form "yyyy-MM-dd" is it?

You could specify a format string of "ddd dd MMMM" but that wouldn't specify where the year should be fetched from. It's not at all clear where TargetDate is coming from, but if you can possibly change the format of that to something more sensible (such as the yyyy-MM-dd you're currently attempting to parse it as) that would be much cleaner.

people

See more on this question at Stackoverflow