How to get the Previous day, First day of month, End of month, and Number of days in month. Power Automate Desktop.

08/28/2023

Japanese version.

This section shows you how to operate the Datetime.

Retrieve the previous day, the first day of the month, the last day of the month, and the number of days in the month.

Procedure

In this example, the date of execution of the flow is targeted for acquisition,

However, it can be applied to other dates by changing the %CurrentDateTime% part of the variable.

Previous day

Set up a "Get current date and time" action to get the date the flow was run.

Set up a "Add to datetime" action.

ParameterValue
Datetime%CurrentDateTime%
Add-1
Time unitDays

When this flow is executed, the date of the previous day is stored in the variable produced by the "Add to datetime" action.

Overall flow

Robin(for copy and paste)

It can be copied and pasted into Power Automate Desktop.

DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateOnly CurrentDateTime=> CurrentDateTime
DateTime.Add DateTime: CurrentDateTime TimeToAdd: -1 TimeUnit: DateTime.TimeUnit.Days ResultedDate=> ResultedDate

First day of month

Set up a "Get current date and time" action to get the date the flow was run.

Set up a "Add to datetime" action.

ParameterValue
Datetime%CurrentDateTime%
Add%-1 * (CurrentDateTime.Day - 1)%
Time unitDays

When this flow is executed, the first date of the month is stored in the variable produced by the "Add to datetime" action.

Overall flow

Robin(for copy and paste)

It can be copied and pasted into Power Automate Desktop.

DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateOnly CurrentDateTime=> CurrentDateTime
DateTime.Add DateTime: CurrentDateTime TimeToAdd: -1 * (CurrentDateTime.Day - 1) TimeUnit: DateTime.TimeUnit.Days ResultedDate=> ResultedDate

Alternate method

It can also be obtained by specifying the following in the "Convert text to datetime" action

ParameterValue
Text to convert%CurrentDateTime.Year + '/' + CurrentDateTime.Month + '/01'%
Overall flow
Robin(for copy and paste)

It can be copied and pasted into Power Automate Desktop.

DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateOnly CurrentDateTime=> CurrentDateTime
Text.ConvertTextToDateTime.ToDateTime Text: CurrentDateTime.Year + '/' + CurrentDateTime.Month + '/01' DateTime=> TextAsDateTime

End of month

First, create the first day of the month as described above, and then put in place the "Add to datetime" action.

Add one month to the first day of the month to create the first day of next month.

ParameterValue
DatetimeFirst day of month
Add1
Time unitMonths

Put in place another "Add to datetime" action.

ParameterValue
DatetimeFirst day of next month
Add-1
Time unitDays

When this flow is executed, the date of the end of the month is stored in the variable produced by the "Add to datetime" action. Initially, the variable name is %ResultedDate3%.

Overall flow

Robin(for copy and paste)

It can be copied and pasted into Power Automate Desktop.

DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateOnly CurrentDateTime=> CurrentDateTime
DateTime.Add DateTime: CurrentDateTime TimeToAdd: -1 * (CurrentDateTime.Day - 1) TimeUnit: DateTime.TimeUnit.Days ResultedDate=> ResultedDate
DateTime.Add DateTime: ResultedDate TimeToAdd: 1 TimeUnit: DateTime.TimeUnit.Months ResultedDate=> ResultedDate2
DateTime.Add DateTime: ResultedDate2 TimeToAdd: -1 TimeUnit: DateTime.TimeUnit.Days ResultedDate=> ResultedDate3

Number of days in month

If the last day of the month is created using the method described above and the day is taken out with the .Day property, it will be the number of days in the month.

%ResultedDate3.Day%

For those who want to learn Power Automate Desktop effectively


The information on this site is now available in an easy-to-read e-book format.

Or Kindle Unlimited (unlimited reading).

You willl discover how to about basic operations.

By the end of this book, you will be equipped with the knowledge you need to use Power Automate Desktop to streamline your workflow.

Table of Contents.

Update History.

Links

Tips(Power Automate Desktop)