Filter datatable column between a date range

Hello All,

i need to filter a column in data table between two dates. Today’s date and +7 days from today date,

I have a column “StartDate” which in Date format in the excel.

I have assigned to two variables
str_firstday = DateTime.Now.ToString(“MM.dd.yyyy”)
str_Seventhday = Now.AddDays(+7).ToString(“MM.dd.yyyy”)

Can you please tell me a to filter “StartDate” column dates between str_firstday and str_Seventhday

Thank you

@Yugal_Raju

Read the data and then in assign use below

requireddt = dt.AsEnumerable.Where(function(x) Cdate(x) > Now AndAlso CDate(x) < Now.AddDays(7)).CopyToDataTable

cheers

@Yugal_Raju

str_firstday=DateTime.Now.ToString("MM.dd.yyyy")
str_Seventhday=DateTime.Now.AddDays(7).ToString("MM.dd.yyyy")

Use Filter datatable activity

<Column Name="StartDate" Operation=">=" Value="str_firstday" />
        <Column Name="StartDate" Operation="<=" Value="str_Seventhday" />

Hi @Yugal_Raju

str_firstday = DateTime.Now.ToString(“M/dd/yyyy”)
str_Seventhday = Now.AddDays(+7).ToString(“M/dd/yyyy”)
DT.AsEnumerable().Where(Function(row) DateTime.Parse(row.Field(Of String)("Date")) >= str_firstday AndAlso DateTime.Parse(row.Field(Of String)("Date")) <= str_Seventhday).CopyToDataTable()

Regards,

Assign today = DateTime.Now
Assign lastdate = today.AddDays(7)

Assign filteredDataTable = (From row In dataTable.AsEnumerable()
                            Where DateTime.Parse(row("StartDate").ToString()) >= today AndAlso DateTime.Parse(row("StartDate").ToString()) <= lastdate
                            Select row).CopyToDataTable()

:slight_smile:

This worked for me , Thank you!

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