Compare months between two dates with Power Automate/Flow

Nov 9, 2020 8:32 PM

aymang

Views

212

Likes

1

Dislikes

0

This is the basic structure of the workflow that will compare the two dates to see if they exist within the same month.

The first variable I created is named insertYourDateHere. You can name it whatever you like. Note that the '11/26/2020' within the formula does not need to be a static value. You can set it so that it corresponds to dates within a certain column on a list. All you need to do is type out "formatDateTime(" then click on the dynamic content from the dropdown below. Then continue typing out the rest of the formula ",'MM')".

If you want to format a date for adding and subtracting days, you would format it as ",'yyyy-MM-ddThh:mm:ssz')". If you want to format a date in a friendly text format (US based) this is how you would enter the format ",'MM/dd/yyyy')".

Initialize a variable to obtain the current date; utcNow().

formatDateTime(utcNow(),'MM') will give you the month in number format.

Add a condition step to compare the two variables that you just created. I added a set variable step after each with a 'Yes' and a 'No' result depending on whether or not the dates match.

If we run the workflow, the current month for both dates is 11. Passing this through the condition check allows us to take the if Yes path.

If we run the workflow, and change the target month to March this changes things. Passing this through the condition check allows us to take the if No path.

powerautomate

flow