Get previous weekend date in UI path Studio X


Can anyone help me on below query

I need to get previous week Sunday date and Saturday date, so for example the dates will be 24th May 2020 i.e Sunday and 30th May 2020 Saturday.

I am working with UI path studio X.

So what logic i need to apply to get the output

So you need two days corresponding to a week, starting on Sunday and ending on Saturday.

The steps you need to take are the following:

  1. Create two System.DateTime variables, lastSaturday and lastSunday
  2. Assign to lastSunday the value Datetime.Now
  3. Create a while loop. Condition: lastSunday.DayOfWeek <> DayOfWeek.Sunday
  4. Inside the loop, assign to lastSunday the value Sunday.AddDays(-1)
    Since you need the last week’s Sunday:
  5. After the loop, assign to lastSunday the value lastSunday.AddDays(-7)
  6. Do the steps 2-4 for lastSaturday. Ignore step no 5 since you don’t need last weeks Saturday.

Now, you should have the two DateTime variable stored.

Best regards

lastSaturdaySunday.xaml (6.7 KB)