Validating Dates in dd-MMM-yyyy format






4.98/5 (31 votes)
This is an alternative to "Validating Dates in dd-MMM-yyyy format"
Less magic, more readable, would be:
DateTime dt1;
DateTime dt2;
if (DateTime.TryParseExact(str1, "dd-MMM-yyyy", null, DateTimeStyles.None, out dt1) &&
DateTime.TryParseExact(str2, "dd-MMM-yyyy", null, DateTimeStyles.None, out dt2)) {
// do something with those datetimes
}