Linq query to check date in a datatable

Hello Everyone,

I need a Linq query for the following datatable.
image
Verify the dt with a date and determine between which start date and end date the following date appears.
For example, a random date (07/14/2022; format: MM/dd/yyyy), that is in the 4th row.

Output as dt,
image
Able to achieve using for each, but it is slow
Thanks in advance

Hi @RVK

Please check the following query:

(
From row in YourDataTable
Where CDate(row(“StartDate”).ToString) >= YourDate AndAlso CDate(row(“EndDate”).ToString) <= YourDate
Select row
).CopyToDataTable

For more about Filter DataTables, please check the following video:

1 Like

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