Power Automate: previous and/or next date/time (hour, month, year, etc.)

There are 2 ways to get the previous and/or the next day, seconds, year, etc. Option 1 is to use “add to time” or “subtract from time”. For my article, I will use the first one (the second one works the same way):

power automate

Click on the “base time” field then click on the “fx” button:

power automate

To put this code (it will get the current date): utcNow()

power automate

Click on “add” then fill the following fields to get the previous month by putting “-1” in the “interval” field:

power automate

NOTE: using “subtract from time”, I have to put “1” instead of “-1”

I will add a new step “compose”:

power automate

Click on the “inputs” field to click on the “fx” button to put: formatDateTime(,'MMMM')

power automate

Click before the coma “,” then “dynamic content” to select this option:

power automate power automate

Once done, click on “add”:

power automate

This step is necessary to format the date correctly, without it, I will get a date in an ISO format. For more format options, read Power Automate: date and time.

Option 2 is to use only “compose” with the function:

  • addToTime()
  • Or subtractFromTime()

so I will add another one. This time, I will put this code for the next year: addToTime(utcNow(),1,'year','yyyy')

power automate

NOTE: using “subtractFromTime”, I have to put “-1” instead of “1”

power automate

The next year is calculated based on the current date:

  • Change the number “1” to get a different year, for instance, by putting “-1”, I will get the last year
  • Change 'year','yyyy' by other types:
    • For “second”: 'second','ss'
    • For “minute”: 'minute','mm'
    • For “hour”: 'hour','HH'
    • For “day”: 'day','dd'
    • For “month”: 'month','MMMM'

Now to have both (option 1 and option 2), I will combine both outputs into a step, for instance, in the “send an email” step into the “subject” and “body” fields:

  • The “compose: outputs” corresponds to option 1
  • The “compose 1: outputs” corresponds to option 2
power automate power automate

Interesting Topics