Date validations from a data table

Hi, I have this excel with Dates Valid column with 2 dates separated by “-” , I need to verify that all rows have dates and the first date (date before the “-”) is less than the second date:
The image displays a table with "Pricing Program" rates and their corresponding validity dates from August 12, 2024, to September 15, 2024. (Captioned by AI)

How can I write this expression in a single line?
Thanks for the help.

HI,

How about the following sample?

arrDr = dt.AsEnumerable.Where(Function(r) not (DateTime.TryParse(System.Text.RegularExpressions.Regex.Match(r("Dates Valid").ToString,".*(?=-)").Value,New DateTime) AndAlso DateTime.TryParse(System.Text.RegularExpressions.Regex.Match(r("Dates Valid").ToString,"(?<=-).*").Value,New DateTime) AndAlso DateTime.Parse(System.Text.RegularExpressions.Regex.Match(r("Dates Valid").ToString,".*(?=-)").Value) < DateTime.Parse(System.Text.RegularExpressions.Regex.Match(r("Dates Valid").ToString,"(?<=-).*").Value) )).ToArray

Sample
Sample20240909-1.zip (9.7 KB)

Regards,

1 Like

Hi

Try this,

Thank you for the help

can we add a check that the table doesn’t contain null in any of the rows to the same expression?

Hi,

Can you try the following sample?

dt.AsEnumerable.Where(Function(r)  r.ItemArray.Any(Function(o) o is Nothing OrElse String.IsNullOrEmpty(o.ToString)) OrElse not (DateTime.TryParse(System.Text.RegularExpressions.Regex.Match(r("Dates Valid").ToString,".*(?=-)").Value,New DateTime) AndAlso DateTime.TryParse(System.Text.RegularExpressions.Regex.Match(r("Dates Valid").ToString,"(?<=-).*").Value,New DateTime) AndAlso DateTime.Parse(System.Text.RegularExpressions.Regex.Match(r("Dates Valid").ToString,".*(?=-)").Value) < DateTime.Parse(System.Text.RegularExpressions.Regex.Match(r("Dates Valid").ToString,"(?<=-).*").Value) )).ToArray

Sample
Sample20240909-1 (2).zip (9.8 KB)

Regards,

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.