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)


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
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

Hi Arpan,
I wanted to extract missing dates from excel … For that can we apply linq query or any other approch

@Minal_U ,

We would request you to create a separate Topic, so that we do not mix things up with the Initial Requirement the post and it’s solution has to offer to other users who are looking for the same issue.

For your query on Missing Dates, Have an Initial look on the post below, but for further discussion do create a Separate Topic :

Have you considering using the “Select” method of the DataTable class? This will return an array of DataRow