“I’d like to add exactly one month to a date in Power Automate. Not 30 days but a full month: 28, 29, 30 or 31 days.”
Like many other operations in Power Automate, you must find the right action or expression to add month(s) to a date. You could use the common addDays(…) expression to add a specific number of days, but what number do you use? Do you use 30 as an average for all months? Even if it’s not 30 each month? That could make a difference in days from the desired date.
What’s the action or expression to use then? Actually, there’re both options: action and expression.
addToTime(…) expression
Let’s take a look on the expression first. Power Automate has an expression addToTime(…) to add various time units. It expects 4 parameters: date, how many units to add, what time units these are, and format.
addToTime([Date], [number], '[units]', '[format]')
example to take today's date, add 12 Months, and format as year-month-date (2021-01-27)
addToTime(utcNow(),12,'Month','yyyy-MM-dd')
Notes:
[Date] is the base date
[number] is a number of the [units] to add
[units] is the time period: Second, Minute, Hour, Day, Week, Month or Year
[format] is optional, it's up to you if you want to format the result in any way
‘Add to time’ action
‘Add to time’ is an action with almost the same functionality. If you don’t want to type in an expression, you can use this action instead.
There’s one downside though, the ‘Add to time’ action doesn’t allow you to format the result date. In case you need the date in a specific format, you must format it later using a separate expression formatDateTime(…).
Summary
As you can see above, Power Automate has often multiple solutions to a problem. One solution is using a specific action, it’s simple and user friendly, but you might miss some functionality.
The other solution, with the expression, might look complicated on the first look, but it gives you more possibilities. You don’t depend on the design of a specific action, you have full access to the underlying expression. In this case it’s the result date format.
Hi Tom. Is it possible for Power Automate to find the next month end? For example today is Nov 30 and the next month would be Dec 31 and not Dec 30. Thank you.
Hello Yannie,
you can use the combination of addToTime(…) and startOfTheMonth(…) expression as described in this post: https://tomriha.com/filter-sharepoint-items-with-date-in-the-same-month-in-power-automate/. Get start day of this month (1st of January), add 2 months (1st of March), and remove 1 minute (28th of February at 23:59).
addMinutes(addToTime(startOfMonth(utcNow()),2,'Month'),-1)
Thank you Tom! Would you know how I would find a date that is “x number of business days away from month end”? For example, I have a column called “Month End” and I want to find the 8th business after that month end date in my flow. Or perhaps you have a separate blog on this topic? Thanks again.
Hello Yannie,
take a look on the new blog post: https://tomriha.com/how-to-add-only-working-days-to-a-date-using-power-automate/
Hi Tom, is it possible to get list of all months and years falling between two given dates in Power automate?
Hello Sam,
I’d guess it is possible, but I have no idea how to do that at this moment. 🙂