DateTime.TryParseExact is failing with 13+ Hrs

Feb 16 2018 5:22 AM
string expirtyDate0 = "12/31/2200 23:59"; - Failed
string expirtyDate1 = "2/31/2200 23:59"; - Failed
string expirtyDate2 = "2/1/2200 23:59"; - Failed
string expirtyDate3 = "1/3/2200 3:59"; - Success
string expirtyDate4 = "1/3/2200 3:9"; - Success
string[] dtFormat = { "MM/dd/yyyy hh:mm", "M/d/yyyy hh:mm", "M/dd/yyyy hh:mm", "MM/d/yyyy hh:mm","MM/dd/yyyy h:mm","MM/dd/yyyy hh:m","MM/dd/yyyy h:m","M/d/yyyy h:mm", "M/d/yyyy hh:m", "M/d/yyyy h:m","M/dd/yyyy h:mm", "M/dd/yyyy hh:m", "M/dd/yyyy h:m","MM/d/yyyy hh:mm", "MM/d/yyyy hh:mm", "MM/d/yyyy hh:mm" };
DateTime expiryDateValue;
if (DateTime.TryParseExact(expirtyDate0, dtFormat, new CultureInfo("en-US"), DateTimeStyles.None, out expiryDateValue))
{
Console.WriteLine("successed");
}
else
{
Console.WriteLine("failed");
}
 
I observed that if we give hh after 12 it's failing. Do we need to any other format

Answers (3)