One of the known issues in Microsoft Flow is to calculate next month’s date. When you use the DateTime connector quite often flow gives you a date that is roughly right. In this post I’m giving a number of steps that can calculate next month’s date.

I’m starting with a Compose step to get the current date and time with the utcNow function. This step of course isn’t really needed. But it makes it easier to explain the solution.

Microsoft Flow - Calculate next month - Resolved with workaround Microsoft Flow, Microsoft Office 365 step1

Then in my second step I will convert the flow to the GMT  time zone. The GMT zone is my local time zone. So you might have to chnage this to your local time zone.

convertFromUtc(outputs('Compose_-_Current_Date_and_Time'),'GMT Standard Time','yyyy-MM-ddTHH:mmZ')

Then I’ll calculate the current day of the month.

convertFromUtc(utcNow(),'GMT Standard Time','dd')

Microsoft Flow - Calculate next month - Resolved with workaround Microsoft Flow, Microsoft Office 365 step3

Then I’ll add a month to my utcTime that I collected earlier.

Microsoft Flow - Calculate next month - Resolved with workaround Microsoft Flow, Microsoft Office 365 step4

Rather than using the above easy to use broken action you could also use the following function:

addToTime(outputs('Compose_-_Current_Date_and_Time'),1,'Month','yyyy-MM-ddTHH:mmZ')

and finally I replace the wrong day with the correct day.

Microsoft Flow - Calculate next month - Resolved with workaround Microsoft Flow, Microsoft Office 365 step5

replace(body('add_to_time'),substring(body('add_to_time'),7,4),concat('-',outputs('Compose_-_Current_Day'),'T'))

Note: Rather than using outputs in the above you could also simply use:

replace(body('add_to_time'),substring(body('add_to_time'),7,4),concat('-',convertFromUtc(utcNow(),'GMT Standard Time','dd'),'T'))

Now I’ve got the following flow that calculates next month.

Microsoft Flow - Calculate next month - Resolved with workaround Microsoft Flow, Microsoft Office 365 5steps

After I’ve optimized my flow a bit by removing the first Compose I’m now  ( at 2018-07-21 15:35 ) getting my next month’s date.

Microsoft Flow - Calculate next month - Resolved with workaround Microsoft Flow, Microsoft Office 365

 

And we could event take this further and use just 1 Compose:

replace(
addToTime(
convertFromUtc(utcNow(),'GMT Standard Time','yyyy-MM-ddTHH:mmZ')
,1,'Month','yyyy-MM-ddTHH:mmZ')
,substring(
addToTime(
convertFromUtc(utcNow(),'GMT Standard Time','yyyy-MM-ddTHH:mmZ')
,1,'Month','yyyy-MM-ddTHH:mmZ')
,7,4),concat('-',convertFromUtc(utcNow(),'GMT Standard Time','dd'),'T'))

Avatar for Pieter Veenstra

By Pieter Veenstra

Business Applications Microsoft MVP working as a Principal Architect at HybrIT Services Ltd. You can contact me using contact@sharepains.com

2 thoughts on “Microsoft Flow – Calculate next month – Resolved with workaround”
  1. I’ve been trying to figure out how to solve this problem but for a variable number of months. I can see how you can easily just add the appropriate variable in the Add Time step, but what happens if the day say April 31 doesn’t exist when you replace the day with the original day.

    1. when adding months results in an invalid date you might have to build in some additional logic. you could always go for some logic that gives you the first day of the next month and remove 24 hours.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from SharePains by Microsoft MVP Pieter Veenstra

Subscribe now to keep reading and get access to the full archive.

Continue Reading

%d bloggers like this: