Power Automate Desktop : Get First Working Day of the Next Month
Get First Working Day of the Next Month
This flow gets the current date and time and calculates the first working day of the following month. If the first day of the month falls on a Saturday or Sunday, the flow automatically selects Monday as the first working day.
Step-by-Step Explanation
-
Get the current date and time
The flow starts by retrieving the current date and time and storing it in the variableNow. -
Add one month to the current date
The flow adds one month toNowand stores the result inNowplus1. This step ensures we are working with the next month. -
Create the first day of next month
The flow constructs a text value using:%Nowplus1.Month%/01/%Nowplus1.Year%
This represents the 1st day of the upcoming month.
It then converts this text into a DateTime variable calledFirstDayOfNextMonth. -
Check the day of the week
A message box displays the actual weekday ofFirstDayOfNextMonth(e.g., Monday, Saturday, etc.).
The flow then evaluates:- If it is Saturday → Add 2 days (next Monday)
- If it is Sunday → Add 1 day (next Monday)
- Otherwise → The first day itself is a working day
-
Show the result
Finally, the flow displays a message showing which weekday is the first working day of next month.
Example: "First working day of next month is Monday"
Full Power Automate Desktop Code
# The following actions get the current datetime and add one month to it.
DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime=> Now
DateTime.Add DateTime: Now TimeToAdd: 1 TimeUnit: DateTime.TimeUnit.Months ResultedDate=> Nowplus1
# Convert text to datetime to get the first day of next month.
Text.ConvertTextToDateTime.ToDateTime Text: $'''%Nowplus1.Month%/01/%Nowplus1.Year% 00:00:01''' DateTime=> FirstDayOfNextMonth
# Show weekday of first day next month
Display.ShowMessageDialog.ShowMessage Title: $'''test''' Message: FirstDayOfNextMonth.DayOfWeek
# Weekend check logic
IF StartsWith(FirstDayOfNextMonth.DayOfWeek, $'''Saturday''', True) THEN
DateTime.Add DateTime: FirstDayOfNextMonth TimeToAdd: 2 TimeUnit: DateTime.TimeUnit.Days ResultedDate=> ResultedDate2
Display.ShowMessageDialog.ShowMessage Title: $'''Working Day''' Message: $'''First working day of next month is %ResultedDate2.DayOfWeek%'''
ELSE IF StartsWith(FirstDayOfNextMonth.DayOfWeek, $'''Sunday''', True) THEN
DateTime.Add DateTime: FirstDayOfNextMonth TimeToAdd: 1 TimeUnit: DateTime.TimeUnit.Days ResultedDate=> ResultedDate1
Display.ShowMessageDialog.ShowMessage Title: $'''Working Day''' Message: $'''First working day of next month is %ResultedDate1.DayOfWeek%'''
ELSE
Display.ShowMessageDialog.ShowMessage Title: $'''Working day info''' Message: $'''First working day of next month is %FirstDayOfNextMonth.DayOfWeek%'''
END
Comments
Post a Comment