Linq to filter "Date" column in datatable

Hi team,

Need help to get Linq to filter column “Date” in datatable.

need datatable where “Date” column should have dates from today to next 6 days(ex : 06/15/2022 to 06/21/2022)

Help!!

1 Like

Hi @anishakotian400 ,

Check the below Query :

DT.AsEnumerable.Where(Function(x)CDate(x("Date").ToString).Date>=Now.Date andAlso CDate(x("Date").ToString).Date<=Now.AddDays(6).Date).CopyToDatatable

hi @anishakotian400

(From r In DT
Where DateTime.Parse(r(" Date").toString).Date.tostring("MM/dd/yyyy")> =Today.AddDays(0).Date.tostring("MM/dd/yyyy")  And
DateTime.Parse(r("Date").toString).Date.tostring("MM/dd/yyyy")  < Today.AddDays(8).Date.tostring("MM/dd/yyyy")
Select r).CopyToDataTable

hope this helps you

Tried given linq. Getting below errror
Error:
Assign: Conversion from string “” to type ‘Date’ is not valid.

there are some blanks, this is the reason most of the time when we do see this message

Have a look below for some analysis techniques and filter out empty values:

:ambulance: :sos: [FirstAid] Datatable: Debug & Analysis invalid DateTime Strings / String to DateTime Parsing Issues - News / Tutorials - UiPath Community Forum

Hi @anishakotian400

did u try the linq i had given