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

  1. Get the current date and time
    The flow starts by retrieving the current date and time and storing it in the variable Now.
  2. Add one month to the current date
    The flow adds one month to Now and stores the result in Nowplus1. This step ensures we are working with the next month.
  3. 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 called FirstDayOfNextMonth.
  4. Check the day of the week
    A message box displays the actual weekday of FirstDayOfNextMonth (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
  5. 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

Popular posts from this blog

Part 1: Creating Code Apps in Power Apps - A step-by-step guide (with real errors I faced & how I fixed them)

Calling Microsoft Graph API from Power Automate Using Azure App Services – Step-by-Step Guide

Step-by-Step Guide: Power Automate Custom Connector Using Graph API from Azure App Service