If you want to check the date you entered on the web application, often
It will be necessary to deal with different inputs, many of which are illegal, and provide a good test method below:
Static Bool Validatedate (String Date, String Format)
{
Try
{
System.globalization.datetimeformatinfo dtfi = new system.globalization.datetimeformatinfo ();
DTFI.ShortdatePattern = Format;
DateTime DT = DateTime.Parsexact (Date, "D", DTFI);
}
Catch (Exception)
{
Return False;
}
Return True;
}
BOOL SUCCESS;
Success = Validatedate ("3403", "MMMM"); // False As 34 IS Not a Valid Month
Success = Validatedate ("3403", "YYMM"); // true
Success = Validatedate ("1212", "MMDD"); // True