How to compare the Date?

I want to compare the date which is coming from data table (After Data scrapping from the Web) and other one which is available in the variable (String Variable) using filter data table.

Can anyone please suggest how to do this?


One of the surest ways is to convert both string to DateTime type using DateTime.ParseExact method and compare them. Can you share specific data?


1 Like

U can use by converting them into datetime using Cdate() or using parse as @Yoichi suggested.

@ImPratham45/@Yoichi - I’m doing data scrapping and after that storing the result into data table (As a sample i have attached the output).

After that I want to apply the filter on the data like the output result should be display the result only the date after 05/01/2020 (MM/DD/YYYY).

Also after filtering the data i want to store the output in datatable.

.Please help me on this.


Use filter datatable activity and then use condition as
ColumnName say here column-2 > cdate(05/01/2020)

@ImPratham45- Thanks for quick response but when I tried the getting below error -


sorry my mistake use date in double quotes
say cdate("05/01/2020)

@ImPratham45 - Now the error gone but in output i’m not getting any records (Zero Records).


what condition you have put is if data in column 2 or 7 is greater that 05/01/2020 then u will get those rows only ryt?

@ImPratham45 - yes, Right.


share that excel i will chk


Can you try the following expression?

targetDate = new Date(2020,5,1)

ExtractDataTable = ExtractDataTable.AsEnumerable.Where(Function(r) DateTime.ParseExact(r("Column-2").toString.Trim,"MM/dd/yyyy hh:mm",nothing)>targetDate OrElse DateTime.ParseExact(r("Column-7").toString.Trim,"MM/dd/yyyy",nothing)>targetDate).CopyToDataTable


@ImPratham45 - Please check.

Excel.xlsx (8.9 KB)

DateChk.xaml (11.2 KB)Excel.xlsx (9.8 KB)

Check out

@ImPratham45 - Thank you but after implementing into my project getting the below error-


That means there is a data with no values in that columns so y can add condition there

@ImPratham45 - Got it. Thanks for your help.

Most Welcome :grinning:

Happy Automation!

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