How to Get Last Date of the Month using Power Automate

Explores methods to find the last date of the month by creating an Instant Cloud Flow with a user-selected date input in Power Automate

Power Automate offer extensive automation capabilities, but working with¬†DateTime functionalities can be challenging. In this blog, we’ll explore various methods and options to determine the last date of the month.

First, create a new Instant Cloud Flow. Next, add a Date input within the trigger, allowing the user to select a date whenever the workflow is triggered. Name this input variable as ‘date‘. For example, the selected Date is 2024-05-15

Manual tigger with date Input

Method 1:

Next, add a Compose action to the workflow and use one of the expression listed below.

 

Compose action to get last date of the month
Expression 1:
addDays(startOfMonth(addToTime(triggerBody()?['date'],1,'Month')),-1)
Output: 2024-05-31T00:00:00.0000000
Expression 2:
addSeconds(startOfMonth(addToTime(triggerBody()?['date'],1,'Month')),-1)
Output: 2024-05-31T23:59:59.0000000
Expression 3:
addMinutes(startOfMonth(addToTime(triggerBody()?['date'],1,'Month')),-1)
Output: 2024-05-31T23:59:00.0000000
Expression 4:
addHours(startOfMonth(addToTime(triggerBody()?['date'],1,'Month')),-1)
Output: 2024-05-31T23:00:00.0000000

Method 2:

Alternatively, instead of using the Compose action, we can achieve the same result by combining two Date actions in Power Automate.
Add to time and Subtract from time.
First, add the ‘Add to time‘ action and configure it with the properties below.
Base Time
triggerBody()?[‘date’]
Interval 1
Time Unit Month

Next, add the¬† ‘Subtract from time‘ action and fill the below properties

Base Time
startOfMonth(body(‘Add_to_time’))
Interval 1
Time Unit Day
Last Date of Month by Actions (Add and Subtract)

After running the workflow, it will product the following ouput,

2024-05-31T00:00:00.0000000

 

 

Shantha Kumar
Shantha Kumar
Articles: 296