Filter out last week data from a datatable

I have 2 variables containing the dates for week start and week end “str_prevSunday” and “str_prevSaturday”
all I want is to filter out the data from “Created” Column between these 2 dates from a datatable
I have this data in datatable

Assuming “dt” is your datatable
Use following LINQ expression in assign:

dt = (From row In dt.AsEnumerable
Where row("Created").ToString("MM/dd/yyyy") >=  str_prevSunday
And row("Created").ToString("MM/dd/yyyy") <= str_prevSaturday
Select row).CopyToDataTable

Cheers

You are missing a closing bracket

Cheers

Check data types of your “str_prev…”
Is it string variable?

Cheers

any idea? or any other way to get this done?

Most likely the “created” column is a “date” value in the excel, which is in fact a “floating-point number whose integral component is the number of days before or after midnight, 30 December 1899, and whose fractional component represents the time on that day divided by 24” - see DateTime.ToOADate Method (System) | Microsoft Learn

Therefore to compare with your start/end date you need convert to same type, OADate.

The following expression should work:

(From row In dt.AsEnumerable
Where row("Created").ToString >= str_prevSunday.ToOADate.ToString And row("Created").ToString <= str_prevSaturday.ToOADate.ToString
Select row).CopyToDataTable

Cheers

@faiqaqureshi90
What we do see in Excel is not mandatory the same in datatable after readin the Excel.
So lets inspect by following:

  • set a breakpoint after the readin the excel data
  • debug and pause on the breakpoint
  • open watch panel / immediate panel
    • type in dt_queryFile.Rows(0)("Created") and share the output with us (e.g. screenshot)

Based on this we can do a suggestion individually to your case

Also check out this acitivity:
https://docs.uipath.com/activities/docs/filter-data-table

Thanks @J0ska
The following worked for me.

(From row In dt.AsEnumerable
Where row(“Created”).ToString >= CDate(str_prevSunday.ToString) And row(“Created”).ToString <= CDate(str_prevSaturday).ToString
Select row).CopyToDataTable

with ToOADate there was some error saying ToOADate is not a string method

Sure! ToOADate is method of DateTime data type, not String. My bad

Cheers

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