Hi, I need to find days of previous week and add it into data table

For e.g. Today is April 13, 2022, Last week date from Sunday to Saturday was
(April 3 (Sunday )to April 9 (Saturday))
Now I need a datatable of prevous week say - dtprevousweek
it should contain dates between Sunday to Saturday of last week
for e.g.
2022-04-03
2022-04-04
2022-04-05
2022-04-06
2022-04-07
2022-04-08
2022-04-09

Any help would be appreciated, Please also add the solution file.
Thanks

@imaredia

Welcome to forums

Can you check below thread for your reference

You can change according to your requirement

Hope this may help you

Thanks

1 Like

Hi @imaredia ,
To Understand the Logic better, Can you let us know the below Info :

If the Today’s Date was April 17, 2022. What would be the Sunday to Saturday Dates ?

Hi, If the todays date is April 17, then last week date will be April 10 (Sunday) to April 16 (Saturday). Always pick last week Sunday to Saturday days and add it into data table.
So my data table will now have
2022-04-10
2022-04-11
2022-04-12
2022-04-13
2022-04-14
2022-04-15
2022-04-16
Thanks

Hi @imaredia ,

You could try the below Steps :
1… Use Build Datatable Activity and Build a One Column Datatable, name the Output Variable as DT.
image

  1. Next, If it is a Custom Date, we would like to Assign that Date to a Variable using Assign Activity like below :
InputDate = Now

where InputDate is of the Type DateTime
image

  1. Next, We can use the below Linq Query to generate the Values in Datatable using an Assign Activity :
DT = (From x In Enumerable.Range(0,7)
Let d = InputDate.AddDays( -InputDate.DayOfWeek - (7 -x))
Select DT.LoadDataRow({d.ToString("yyyy-MM-dd")},False)).CopyToDataTable

image

The Output appears like below :
image

This should be the Required Output. Let us know if you are still facing issues.

This is perfect, This is exactly what I was looking for, You did it in very simple steps using less code, I did it in a lengthy code, I updated my code with yours.

Thanks

1 Like