Reputation: 5384
I'm getting this STRING value from a code written in the UK
"15:11 PM Friday, February 20, 2"
and try to convert it to a DateTime using Convert.ToDateTime("string value")
I get an Exception stating that String was not recognized as a valid DateTime because the day of week was incorrect.
The 20th was a Friday on February 2015. Is the problem the fact that we are missing the YEAR?
Upvotes: 1
Views: 2527
Reputation: 49974
Technically the error message is correct - the day of the week is incorrect if you are dealing with the year 2
.
The UK uses dates just like the rest of the civilised world (I exclude the USA and any other country that uses mm/dd/yy from the set of "civilised"), so I would be checking why you are missing the rest of the year.
Upvotes: 2
Reputation: 44439
The return value is the result of invoking the
DateTime.Parse
method on value using the formatting information in aDateTimeFormatInfo
object that is initialized for the current culture.
Look at the formats in there and you'll very likely not find one without the year specified. Add your own to it or parse it with a format directly.
Upvotes: 2