Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

Validating Dates in dd-MMM-yyyy format

4.98/5 (32 votes)
13 May 2010CPOL 26K  
This is an alternative to Validating Dates in dd-MMM-yyyy format

Less magic, more readable, would be:

C#
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
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)