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
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
You could try the below Steps :
1… Use Build Datatable Activity and Build a One Column Datatable, name the Output Variable as DT.
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
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
The Output appears like below :
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.