AaronMark
(AaronMark)
February 2, 2021, 10:40am
1
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.
So, regardless of the bot’s RUN day, the range date of the previous week.
Can anyone help me with this please?
thanks…
Aaron
ptrobot
February 2, 2021, 11:08am
2
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")
4 Likes
ppr
(Peter Preuss)
February 2, 2021, 11:12am
3
Variables:
Flow:
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:
1 Like
AaronMark
(AaronMark)
February 2, 2021, 11:41am
5
Hi ptrobot,
This works fine.
Now I still want to understand the second example of ppr.
1 Like
AaronMark
(AaronMark)
February 2, 2021, 11:43am
6
@ppr ,
Maybe I didn’t understand how to use the string.
I made this:
but the write line:
How do I recall the two values, separately.
ppr
(Peter Preuss)
February 2, 2021, 11:44am
7
just let me check some few things in advance
ppr
(Peter Preuss)
February 2, 2021, 12:19pm
8
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)
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
AaronMark
(AaronMark)
February 2, 2021, 1:38pm
9
@ppr
Maybe a little too complex for me.
I can’t get it to work.
system
(system)
Closed
February 5, 2021, 1:39pm
10
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.