Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the easiest way to validate this date format, eg, 31-JUL-2010 (and only this fmt)

Tags:

vb.net

I would like to easily validate dates in this format and only this format. Any otehr format should be considered invalid.

like image 360
Chad Avatar asked Dec 04 '25 21:12

Chad


2 Answers

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);
like image 99
Oded Avatar answered Dec 08 '25 14:12

Oded


Dim DateToTest As String = "01-Apr-1964"
Dim ResultDate As Date

Date.TryParseExact(DateToTest, "dd-MMM-yyyy", Globalization.CultureInfo.InvariantCulture, Globalization.DateTimeStyles.AllowWhiteSpaces, ResultDate)
like image 36
Chad Avatar answered Dec 08 '25 14:12

Chad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!