I’ve seen a lot of posts similar to this but none with the right answer for my question. The robot I’m writing needs to pull reports for the most recent Wednesday - Tuesday period. I figured I could just get the previous Tuesday and -6 days to get the Wednesday before that. The issue I’m running into is that all the formulas I find in these forum posts get the Tuesday of the previous week (or current week). but i need the previous Tuesday, whatever week it happens to be in (the last concluded Tuesday, so, if today was Tuesday, I still want it to get the previous concluded Tuesday; in this case, Tuesday last week).
Edit: I don’t need the date range. I need the dates individually in separate variables.
where
x1 - Offset from a Sunday to the targeted Tuesday / Wednesday
x2 - Offset from a Monday to the targeted Tuesday / Wednesday
…
x7 - Offset from a Saturday to the targeted Tuesday / Wednesday
I have tried that one and it works as long as it isn’t the current day. I want this to still get last Tuesday if today is Tuesday. Since today is Monday, I tried your recommendation with “Monday” instead of “Tuesday” to see if it would work but it gave me today’s date when I would want last Monday’s date in this case (because I need the last completed Monday).
@ppr What is your myDate variable supposed to be? I’m not sure how to implement your code: does it go in an Assign? default variable value? How does it know which part of the array to use?
Assume today is Wednesday, April 3. I want to pull data from last Wednesday (March 27) through yesterday (Tuesday, April 2).
Now assume today is Saturday, March 30. I still want to pull the same date range of data: March 27 - April 2
Now assume today is Tuesday, April 9, I still want it to pull the same date range of data: March 27 - April 2 (because even though today is Tuesday, it is not over, so it will be included in the next Wednesday-Tuesday period run (April 3 - April 9).
So far, the closest I’ve come to getting the correct date for the previous Tuesday is what @muktadir recommended above. However (using previous example), it does not work if today was Tuesday, April 9. That formula would return April 9, instead of the desired April 2.
@muktadir I am a little confused. The code pasted at the beginning of your response says “dayofweek.tuesday” but the screenshot shows “dayofweek.monday” which of these are you suggesting I use? and is it supposed to be giving me the date of the previous Wednesday or Tuesday?
@JoKerCoder
Please ignore the previous answer it had some error. the reason you see monday in screenshot is becasue i am testing the code with monday and since you need the date for tueday i am editing the expression
If i rn for monday
CDate(DateTime.Today.AddDays(-1 * ((DateTime.Today.DayOfWeek - DayOfWeek.Tuesday+ 7) Mod 7 + 7))).ToShortDateString()
@muktadir That is close but it only works if today were Monday and I was looking for last Monday. I’m still running into the problem of it not getting the correct Monday date if today were Tuesday and I wanted to include yesterday (Monday) in my query, your code would give me the date for 2 Mondays ago, which would be incorrect.
Basically, I need my code to result in the date of the most recent Tuesday that is NOT today (if today were Tuesday). I’m thinking I may need to just set the value of my date variable based on an If statement…
@ppr Ok I think I almost understand what you’re doing. However, it seems that you are expecting me to manually insert a date for the myDate variable, but I don’t want to have to enter a date each time this bot is ran. I’d like it to take today’s date (whatever day it is being ran) and find the appropriate date for the most recent Tuesday that is not today (if today were Tuesday), then I know I could just subtract 6 to get the Wednesday before that.
Secondly, I think you are saying that I need to change the array depending on when it’s ran, if I understand you correctly. Having to intermittently change the code like that is not desirable.
I’m thinking maybe an If activity that changes the date variables depending on what today is will probably be the right answer here…?
ok, finally understood how to implement your suggestion. I got the array to give me the correct Tuesday end date by ordering it as {5,6,7,1,2,3,4}. Then I subtract 6 from that to give me the correct Wednesday start date. Thanks, @ppr
I’m attaching the .xaml for your reference just check it once! Main.xaml (10.0 KB)
Hope it will be helpful to you.
If you find this solution easier and more convenient then you can mark this post as a solution as well, it will be beneficial for others to get an easy & optimized solution!
Thank you for this! I didn’t know about this either, but @ppr’s reply is more of what I was looking for for this particular case. I wanted something I could set as a default argument value so I could bring in specific dates from Orchestrator if necessary.
I can already think of a couple of other of my processes that could use your suggestion. Thanks again.