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:
How can I write this expression in a single line?
Thanks for the help.
Yoichi
(Yoichi)
September 8, 2024, 11:38pm
2
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
can we add a check that the table doesn’t contain null in any of the rows to the same expression?
Yoichi
(Yoichi)
September 9, 2024, 3:30am
6
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,
system
(system)
Closed
September 12, 2024, 3:31am
7
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.