How to Get Current and Previous Month in Power Automate?

In our recent project, a client asked me to retrieve the current month’s name and number using Power Automate. While researching this, I learned that the Power Automate formatDateTime() function and the utcNow() can help to achieve this.

In this article, I will explain how to get current and previous month in Power Automate. Additionally, we will discuss some more topics below:

  • Get the current month number in Power Automate
  • How to obtain the current month’s name in Power Automate
  • Retrieve the current month’s abbreviation in Power Automate
  • Get the previous month in Power Automate
  • Retrieve the last month’s name using Power Automate
  • How to get the start day of the last month using Power Automate
  • How to get the last day of the last month using Power Automate

Get Current Month in Power Automate

Power Automate formatDateTime() function can retrieve the current month using utcNow in a flow. With this function, a user can display a particular date and time format irrespective of the user’s system settings.

Formats for Month that can include in formatDateTime() function:

MMMM- Month name -October
MMM- Month abbreviation -Oct
MM-Month number -10

A step-by-step guide to get the current month in Power Automate flow:

Get Current Month Number in Power Automate

Open a Power Automate Home page by logging through your Microsoft credentials. Next, create a manual trigger flow in Flow Studio. Then, take an Initialized variable and fill in the below details:

  • Name: Give a name for an initialized variable.
  • Type: Select datatype from the drop-down.
  • Value: Provide the below code in the value section.
int(formatDateTime(utcNow(),'MM'))
How to get the current month in Power Automate

To see the output, add a Compose data operation and take the Input value generated from an initialized variable.

@{variables('Current Month Number')}
Get the current month in Power Automate

Get Current Month Name in Power Automate

Let us see how to get the current month’s name in Power Automate.

  • In the initialized variable, set the below details:
    • Name: Provide a name for an initialized variable.
    • Type: Select datatype as ‘String ‘ from the drop-down.
    • Value: Provide the expression given below in the value column.
formatDateTime(utcNow(),'MMMM')
Power Automate Get the Current month in a flow
  • In the Compose action, take value from the dynamic content of variables as shown below:
@{variables('Current Month')}
Power Automate flow Get the Current month

Get Current Month Abbreviation in Power Automate

  • Similarly, set the Value of an initialized variable as given in the code below.
    • Name: Give a name for the variable.
    • Type: Select a data type as ‘ String ‘from the drop-down.
formatDateTime(utcNow(),'MMM')
Power Automate obtain the Current month in a flow
  • To check the output, add Compose action and give below details:
    • Inputs: Select the output value that comes with variables under dynamic content.
@{variables('Current Month')}
Retrieve current month in Power Automate
  • Once the flow has been created, click on Save and Test Manually.
Get Current Month name in Power Automate

Today’s Date is 11-10-2023 (dd-MM-yyyy) format.

The below image shows the output for the current month’s number:

Power Automate include current month in a path

The image placed below will represent the output for the current month’s name:

Power Automate formatDateTime get current month

Below shown screenshot will display the output for the current month’s abbreviation:

How to get month in various formats from date in Power Automate

This is how to get the current month in Power Automate using the formatDateTime() function.

Get Previous Month in Power Automate

Let us check out how to get the previous month in Power Automate. I have taken four examples based on the previous month in Power Automate.

1. Navigate to https://make.powerautomate.com/ and click on + Create -> select “Instant cloud flow”. In the next window, provide a flow name, select “Manually trigger a flow”, and click on Create.

2. Next, add an “Initialized variable” to store the value and be used during the flow. Here, provide the details below:

  • Name: Set a name for an initialized variable.
  • Type: Select datatype as String from the drop-down.
  • Value: Add the below code in value.
addToTime(utcNow(),-1,'month','yyyy-MM-dd')
How to get the previous month in Power Automate

3. Then, add a Compose data operation to check the output from an initialized variable.

  • Inputs: Select output from variables under dynamic content.
@{variables('Previous Month')}
Get the previous month in Power Automate

4. The flow is ready, and we can test it. Save the flow and Click on Test -> Manually to test flow.

Use Power Automate Functions to get previous month

5. This is the output received from the compose flow action i.e. Previous Month Date.

Power Automate Get the previous month in a flow

This is how to get the previous month using the formatDateTime() in a Power Automate flow.

Get Previous Month Name Using Power Automate

Similarly, based on the current date (13-10-2023) in Power Automate, I will show you how to get the previous month’s name in a flow.

Let us get the previous month’s name based on the utcNow() function using the add to Time formula in a Power Automate flow.

Follow the below step-by-step instructions to create an instant cloud flow:

1. Click App Launcher -> Select Power Automate and click on +Create -> Select “Instant cloud flow.” In the next window, provide a flow name, choose “Manually trigger a flow” and click on Create.

2. When the trigger is added to the flow, select an “Initialized variable” flow action and set the details below.

  • Name: Set a name for a variable.
  • Type: Select datatype as ‘String’ from drop-down.
  • Value: Provide the below expression in value.
addToTime(utcNow(),-1,'month','MMMM')
Power Automate flow Get the previous month name

3. Then, add a “Compose” data operation and give input value from the dynamic content of an initialized variable.

@{variables('Previous Month Name')}
Power Automate obtains the previous month in a flow

4. Once the flow has been created. Save it. Click on Test -> Manually to test flow.

Power Automate flow obtains the previous month name

5. The output generated from the initialized variable will display the previous month’s name.

Get the previous month name from the current date in Power Automate

This is how to work on the Power Automate formatDateTime() function to get the previous month’s name inside a flow.

Get the Start Day Of the Previous Month in Power Automate

Now, I will show you how to get the start day of the previous month in a Power Automate flow based on the current date (13-10-2023).

Here, I will follow the same steps to create a Power Automate flow, but this time, I will use a different function in an initialized variable to get the start day of the previous month.

Follow the below instructions to build a Power Automate flow.

1. In the initialized variable, provide the below expression in value and set details like:

  • Name: Provide a name for a variable.
  • Type: Select datatype from the drop-down.
  • Value: Add the code below to the value section.
startOfMonth(addToTime(utcNow(),-1,'Month'),'MMM dd,yyyy')
How to get start day of previous month in Power Automate

2. Next, add a Compose data operation to check the output from an initialized variable.

  • Inputs: Select output from dynamic content.
@{variables('Previous Month')}
 Extract start day of previous month in Power Automate

3. The outputs of compose will show the start day of a previous month inside a flow.

Power Automate flow Extract start day of previous month

This is how to extract the start day of a previous month using Power Automate flow.

Get the Last Day Of the Previous Month in Power Automate

In this section, I will explain the final example, i.e., Power Automate, of how to get the previous month’s last day using a flow.

Follow the above-mentioned steps to create a Power Automate flow that will retrieve the last day of the previous month using the utcNow() function.

This means it will get the previous month’s last day, i.e. (30- Sep-2023) with the current date (14-10-2023).

1. Add the code below to the value section in the initialized variable.

subtractFromTime(startOfMonth(addToTime(utcNow(),0,'month')),1,'day','dddd, MMMM dd,yyyy')
Power Automate Flow Obtain previous month last day

2. Then, add a Compose data operation to check the output from an initialized variable.

@{variables('Last day')}
Power Automate Return previous month last day

3. The compose outputs will show the last day of a previous month inside a flow.

MIcrosoft flow to Return previous month last day

This is how to get the last day of a previous month by using Power Automate functions inside a flow.

Conclusion

Now, I hope you know how to get the names of the current and previous months in Power Automate. We also discussed how to get the start day and last day of the previous month using Power Automate.

You may also like:

>

Build a High-Performance Project Management Site in SharePoint Online

User registration Power Apps canvas app

DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App

Power Platform Tutorial FREE PDF Download

FREE Power Platform Tutorial PDF

Download 135 Pages FREE PDF on Microsoft Power Platform Tutorial. Learn Now…