Verify format of records in dataTable

I need to verify if the dates(as string value) in data table are in format DDMMMYY or not. If not the bot will stop. There are 5 columns which have dates and around 500+rows in the data table.

Please suggest for solution.

You could try something like DateTime.TryParseExact.
Look at this samples VB.NET code. If the DateTime.TryParse is true, than your string is a valid date with format “DDMMMYY”.

 If DateTime.TryParseExact("02FEB22", "DDMMMYY",
                           DateTimeStyles.None, outputDateTimeVar) Then
    Console.WriteLine("Success! {0}", outputDateTimeVar.ToString)
End If

Either way, I see no other way than to check the whole datatable, row by row, looping through it.
But as the datatable has around 500 rows, this shouldn’t be an issue performance wise.


find starter help here for checking in one run all dates not conform to the expected dateformat:
FilterDates_NonValidDateFormat.xaml (8.0 KB)

you can modify the statement to get back a true or false if all dates are ok like this:

dtData.AsEnumerable.All(Function (d) DateTime.TryParseExact(d(ColNameOrIndex).toString, Formats, CultureInfo.InvariantCulture, DateTimeStyles.None, Nothing)).toList
1 Like

Awesome solution, I love how much I learn here event when trying to help others :slight_smile:

extending it to multiple columns:

(From d In dtData.AsEnumerable
Let rc = {0,2,5,7,8}.All(Function (i) DateTime.TryParseExact(d(i).toString, Formats, CultureInfo.InvariantCulture, DateTimeStyles.None, Nothing))
Select b=rc).All(Function (x) x)
1 Like