Get last weekday

Hi there,
Please assume there is a textbox that requires user to enter a weekday (Sunday/Monday/Tuesday/Wednesday/Thursday/Friday/Saturday).
Based on the input, select the last weekday.

Hi @niro

Do you always want a last a previous Tuesday?

Hi @niro

You can use this Today.AddDays(-4-Weekday(Today))
Assign it to a datetime variable.

Thank you,
Prashant

Hi Prasanth, I just edited my question to a better one. I would want the day to be dynamic, so I can’t use constant such as AddDays - digit. I need some other way to identify the intended previous weekday

Try You can use this Today.AddDays(-4-Weekday(Today))
Assign it to a datetime variable.
this

It is dynamic in nature.

Quick n dirty Demo on the Main Logic of retrieving the previous Workday
grafik

Sunday: -3
Mo: -4
Tue-Fr: -1
Saturday: -2
grafik

Running test:

Kindly note: Topic Title: previous Workday vs. Description Friday-Tuesday. However the offset can be adopted within the Array: First Position (0) = Sunday, Mon, Tue…, Sat)

3 Likes

I’m sorry, I just had a tough time explaining. How would this work for the below?
Please assume there is a textbox that requires user to enter a weekday (Sunday/Monday/Tuesday/Wednesday/Thursday/Friday/Saturday).
Based on the input, select the last weekday.

@niro
please give us exact details on your case, selectbox …

the substraction should be done on todays date?

2 Likes

based on the input by user. if user enters Monday, the robot should return last Monday. it does not matter what day it is today, it should just return the previous weekday according to the user input

Ok, but is a different requirement. So case is about:

  • Select dayname from input dialog
  • return day of dayname from last week

Right?

Yes. Return the date of dayname from last week

ListCheckDate.xaml (9.0 KB)
Check this and let me know if it is working as expected.

1 Like

@niro
Variables:

Flow:
grafik

idxDay = Array.IndexOf(arrDayNames,selectedDayName) + 1
Offset =(idxDay - IF(today.DayOfWeek=6,7,today.DayOfWeek)) - 7
DateLastWeek = Today.AddDays(Offset)

Find starter Help here:
GetLastWeekDay_ByDayName_FromToday.xaml (6.5 KB)

3 Likes

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