given:
DateTime parsedDate;
if (DateTime.TryParseExact("0992012", "ddMyyyy", null, DateTimeStyles.NoCurrentDateDefault, out parsedDate))
{
Debug.WriteLine("YES");
}
else
{
Debug.WriteLine("NO");
}
Why is the output NO? Is this a bug?
That’s a bad format, basically – I don’t know whether it’s specified whether or not it should be accepted, but including a variable-width numeric field beside other numeric fields without any delimiters is a really bad idea.
I suspect the parser sees this as 09 followed by 92 in a “take 1 or 2 digits for the month” and doesn’t realize that the 2 is meant to belong to the year part. That’s what the Noda Time parser would do, at least…
If you can’t change your input format, you should massage the data in-place before trying to parse it – e.g.