I would like to easily validate dates in this format and only this format. Any otehr format should be considered invalid.
You use DateTime.ParseExact or DateTime.TryParseExact. You pass through the exact format string.
In your case the format string would be d-MMM-yyyy (see here) and can be used as follows:
string dateString = "31-JUL-2010";
string format = "d-MMM-yyyy";
DateTime result = DateTime.ParseExact(dateString, format, CultureInfo.InvariantCulture);
Dim DateToTest As String = "01-Apr-1964"
Dim ResultDate As Date
Date.TryParseExact(DateToTest, "dd-MMM-yyyy", Globalization.CultureInfo.InvariantCulture, Globalization.DateTimeStyles.AllowWhiteSpaces, ResultDate)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With