How add or subtract weeks, months or years from a date in Power automate.

Welcome to all of my readers. I am back with another blog on Power Automate.

This blog is rather simple and one of the most common requirements we may come across in our day to day work. How do I add or subtract weeks/ months/ years from a timestamp?

We have the popular addHours, addMinutes, addSeconds function in power automate. But not similar functions for weeks, months or years.

There are couple of lesser known functions addToTime and subtractFromTime to help us out in this scenario. Actually a single function can do the job for both adding or removing an interval. Both has the same construct.

  • Parameter1 – The timestamp
  • Parameter2 – The interval
  • Parameter3 – Time Unit. Can be  “Second”, “Minute”, “Hour”, “Day”, “Week”, “Month”, “Year”
  • Parameter4 – Output date format

Let’s first try with subtractFromTime function.

The following expression will take you back a week from the current timestamp

subtractFromTime(utcNow(),1,'Week', 'dd-MM-yyyy')

The following expressions will deduct couple of months and years from the current timestamp.

subtractFromTime(utcNow(),2,'Month', 'dd-MM-yyyy')  -- month
subtractFromTime(utcNow(),2,'Year', 'dd-MM-yyyy') -- year

The function addToMonth has similar construct and is used for adding the specified intervals to the current timestamp.

addToTime(utcNow(),2,'Week', 'dd-MM-yyyy')
addToTime(utcNow(),2,'Month', 'dd-MM-yyyy')
addToTime(utcNow(),2,'Year', 'dd-MM-yyyy')

In fact the functions can be used interchangeably. For example – the addToTime function can be used to deduct a time unit by specifying a negative interval. The following expression shall deduct couple of years from the current timestamp. Notice I am using the addToTime function with a negative value for the interval.

addToTime(utcNow(),-2,'Year', 'dd-MM-yyyy')

Cool isn’t it?

Hope this helped. You will also like the below posts.

Debajit Dutta
Business Solutions MVP