The easiest way to check this date format, for example 31-JUL-2010 (and only this fmt)

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

+3
source share
3 answers

You use DateTime.ParseExactor DateTime.TryParseExact. You go through the exact format string.

In your case, the format string will 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);
+5
source
Dim DateToTest As String = "01-Apr-1964"
Dim ResultDate As Date

Date.TryParseExact(DateToTest, "dd-MMM-yyyy", Globalization.CultureInfo.InvariantCulture, Globalization.DateTimeStyles.AllowWhiteSpaces, ResultDate)
+3
source

, VB.NET, :

/[0-9] {2} - [A-Za-Z] {3} - [0-9] {4}/

, .

+1

Source: https://habr.com/ru/post/1742568/


All Articles