Get data from the last week

Hi,

I have a csv file with has a bunch of columns. One of the columns has Start Date and i’d like to pull each of the rows which has the date mentioned within the last 7 days.

I have tried the following & i’m getting weird results:

d2 (as DateTime variable) = DateTime.ParseExact(now.AddDays(-7).ToString(“dd/MM/yyyy”),“dd/MM/yyyy”,system.Globalization.DateTimeFormatInfo.InvariantInfo)

Get Row activity (to pick up the row from CSV file & i’ve set output as d1 (datetime variable))

Then, i’ve declared a string variable FormatStartDate = d1.ToString(“dd/MM/yyyy”)

Within my condition, i have if d1>d2, add to dt

With this though, i’m getting data from the last few days as well as data from last year. Any ideas?

1 Like

Buddy @qwerty1
lets take like this
you got your startdate value from each of the rows as you said like this (of type datetime)

start_date = Datetime.Parseexact(d1,“dd/MM/yyyy”,System.Globalization.CultureInfo.InvariantCulture)

then you want to check with 7 days before
now in if condition put like this buddy
start_date > now.AddDays(-7)

Cheers @qwerty1

1 Like

Hi,

Thanks for coming back to me. I’ve implemented your fix & although i’m not getting any errors in UiPath, the output isn’t as expected. I only seem to be getting one result written to the csv rather than the 4 I was expecting from the ‘for each row’ activity.

No worries
Buddy if possible may i have a view on your csv file buddy or even the xaml if possible
This could solve our issue buddy
Cheers @qwerty1

1 Like

I’m grateful for your help but unfortunately i can’t share as its a project for work.

Fine, may i know the date sample from that if possible
Cheers @qwerty1

1 Like

Sure, I have something similar to the data below:

Employee number | Start Date
123 | 05/04/2018
456 | 21/05/2019
789 | 23/05/2019

At the moment, the output is only showing record 456 rather than 456 & 789 as they were both within the last week.

1 Like

Buddy that should work buddy
is your system time is correct buddy, just for clarification
Kindly check once with write line activity with this
now.tostring @qwerty1

Cheers @qwerty1

1 Like

Yeah, from what i can see it initially captures the date in US format (even after i’ve passed it through Datetime.Parseexact(d1,“dd/MM/yyyy”,System.Globalization.CultureInfo.InvariantCulture) ) but other than that, my write line within the for each row just prints one single output rather than all the entries that match the condition :frowning:

So… i think i didn’t get it exactly buddy @qwerty1
you mean you are validating with US time
Cheers @qwerty1

Whoops, sorry - all my dates (in the CSV and from what i’ve manipulated in UiPath) are UK dates (do dd/MM/yyyy). But in my for each row activity, i have an If statement where the condition is as you’d said start_date > now.AddDays(-7)
Within that, i have my Write line "Start Date: " + start_date.ToString + "Last week: " + now.AddDays(-7).ToString and thats printing in US format (unless i add .(“dd/MM/yyyy”)). I’m unsure if that means that UiPath is still ‘seeing’ the date in US format in some way, or if thats just normal (even after the dates been updated)

1 Like

Buddy, usually Invariant = US is what meant for the most part, as mostly all standards were US-centric.
cheers @qwerty1

1 Like

ok, thanks for your help anyways. I’ll try to play around with the data - must be an issue with the csv file then.

1 Like

Fine buddy @qwerty1
cheers

1 Like

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