Filter data table by all dates after start date

I have a column that stores dates. I would like to filter out rows that the date is less than a start date.

I have tried this:

foreignAP_DT.Select("[Due Date] >= #"+startDate.ToString+"#").CopyToDataTable

I am getting an error:
Assign: Cannot perform ‘>=’ operation on System.String and System.DateTime.

Start Date is a DateTime variable.

Example data in Excel. Date format dd/MM/yyyy.

Hi there @Nelson.R,
I hope you are well!

Can you try the below:
Assign - foreignAP_DT = foreignAP_DT.AsEnumerable().Where(Function (drRow) DateTime.Parse(drRow.Item("Due Date").ToString, Nothing, Nothing) <= startDate).CopyToDataTable

This will convert the row value of Due Date into a date, before performing the comparison.

Worth noting, you likely wants to incorporate an If beforehand, to check items exist:
If - foreignAP_DT.AsEnumerable().Any(Function (drRow) DateTime.Parse(drRow.Item("Due Date").ToString, Nothing, Nothing) <= startDate))

Thanks in advance for your support,

@Mr_JDavey Thanks for the response. I believe I found the issue when trying your code. The cause is because some dates that were read from the excel are strings so the comparison gave an error.

Glad you got it solved regardless @Nelson.R - Happy automating!

Thanks once again,

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