How to get range date "Monday-Friday" of the previous week

Hi to all,
I’m not very good at programming, and have a problem finding a specific date range.

I should develop a BOT that will theoretically go into action every Monday and maybe every Tuesday, but,
regardless, I need to collect the range-date from “Monday” to “Friday” of the previous week just ended.

These two dates, I have to use them to set up a search query on SAP.

image

So, regardless of the bot’s RUN day, the range date of the previous week.
Can anyone help me with this please?

thanks…
Aaron

Define three variables of type System.DateTime: lastWeek, lastWeekMonday, lastWeekFriday
Use the Assign activity to calculate the dates:

lastWeek = Now.AddDays(-7)
lastWeekMonday = lastWeek.AddDays(DayOfWeek.Monday - If(lastWeek.DayOfWeek = DayOfWeek.Sunday, 7, lastWeek.DayOfWeek))
lastWeekFriday = lastWeekMonday.AddDays(4)

You can convert them to string like this:

lastWeekMonday.ToString("dd.MM.yyyy")
lastWeekFriday.ToString("dd.MM.yyyy")
3 Likes

Variables:

Flow:
grafik

LINQ:
(From i In {0,4}
Let offset = If(TestDate.DayOfWeek = 0, 7, TestDate.DayOfWeek )
Select TestDate.AddDays(1-offset - 7 + i)).toList

Access:
first element in list is Monday - DateRange(0)
second element in List is Friday - DateRange(1)

Testresult:
grafik

1 Like

Hi ptrobot,
This works fine.
Now I still want to understand the second example of ppr.

1 Like

@ppr,
Maybe I didn’t understand how to use the string.
I made this:

but the write line: image

How do I recall the two values, separately.

just let me check some few things in advance

as Sunday is 0 by the result of xx.DayOfWeek it was jumping to quick into the next week.

@ptrobot did recognized very well and I combined our 2 approaches . See the corrected code above in the updated post

Access can be done as following

Quick Output (But in general we do debug and inspect)
grafik

and if it is wished that the result is directly as formatted string is retrieved then use following:

DateRangeAsString =

(From i In {0,4}
Let offset = If(TestDate.DayOfWeek = 0, 7, TestDate.DayOfWeek )
Select TestDate.AddDays(1-offset - 7 + i).toString("dd.MM.yyyy")).toList

grafik

@ppr
Maybe a little too complex for me.
I can’t get it to work. :expressionless:

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