Power Automate SubtractFromTime Function & Action Explained

Power Automate SubtractFromTime Function Action

The Power Automate subtractFromTime function lets you travel to the past. Calculate the date of tomorrow, next week, next month or next year! Within your Power Automate subtractFromTime expressions, you simply provide what time interval you want to subtract and how often.

There is also the Power Automate Subtract from time action, which is a little easier to use, but does the same thing.

When should you use the function, and when should you use the function?

I would use the function most of the time, because I like to keep my flows small. Adding the action means another step in your Microsoft flow.

But if your flow is very small or the action is an important step in your flow, go for the action.

In the end, it is a matter of taste.

Power Automate SubtractFromTime Function

Power Automate subtractFromTime Function

The Power Automate subtractFromTime function lets you subtract time from a given timestamp. (For example 5 minutes, a day, a week, o month or a year)

Syntax

subtractFromTime('<timestamp>', <interval>, '<timeUnit>', '<format>'?)

Input parameters

  • timestamp (mandatory): The timestamp to subtract time from.
  • interval (mandatory): The time interval that should be used in the subtraction (Second | Minute | Hour | Day | Week | Month | Year).
  • timeUnit (mandatory): The number of time units for the given interval to be subtracted of the given timestamp.
  • format (optional): A format string to define the output format. (For details, take a look at: How to format date and time in Power Automate)

Return value

  • The timestamp string resulting of the subtraction, optionally formatted by the given format.

Power Automate SubtractFromTime Expression Examples

Second

// 5 secondes ago / subtract 5 seconds from now
// utcNow() = Monday, August 22, 2022 6:42:24 PM

subtractFromTime(utcNow(),5,'Second','F')
=> Monday, August 22, 2022 6:42:19 PM

Minute

// 5 minutes ago / subtract 5 minutes from now
// utcNow() = Monday, August 22, 2022 6:42:24 PM

subtractFromTime(utcNow(),5,'Minute','F')
=> Monday, August 22, 2022 6:37:24 PM

Hour

// 5 hours ago / subtract 5 hours from now
// utcNow() = Monday, August 22, 2022 6:42:24 PM

subtractFromTime(utcNow(),5,'Hour','F')
=> Monday, August 22, 2022 1:42:24 PM

Day

// yesterday / subtract one day from now
// utcNow() = Monday, August 22, 2022 6:42:24 PM

subtractFromTime(utcNow(),1,'Day','F')
=> Sunday, August 21, 2022 6:42:24 PM

Week

// one week ago / subtract one week from now
// utcNow() = Monday, August 22, 2022 6:42:24 PM

subtractFromTime(utcNow(),1,'Week','F')
=> Monday, August 15, 2022 6:42:24 PM

Month

// one month ago / subtract one month from now
// utcNow() = Monday, August 22, 2022 6:42:24 PM

subtractFromTime(utcNow(),1,'Month','F')
=> Friday, July 22, 2022 6:42:24 PM

Year

// one year ago / subtract one year from now
// utcNow() = Monday, August 22, 2022 6:42:24 PM

subtractFromTime(utcNow(),1,'Year','F')
=> Sunday, August 22, 2021 6:42:24 PM

How To Use Power Automate Subtract From Time Action

In this example, we subtract 5 minutes from the current time with the Subtract from time action. See step-by-step how to use Power Automate Subtract from time action.

  1. Create a new flow with ‘Manually trigger a flow’

    Power Automate Add to time Action New Flow 1

    Create new flow

  2. Add a Current Time action step

    Power Automate Subtract from time action Add Current Time Action

    Add Current Time action

  3. Add Subtract from time action step

    Power Automate Subtract from time action new step

    Power Automate Subtract from time

  4. Power Automate Subtract from time action configuration

    Power Automate Subtract from time action

    Power Automate Subtract from time action configuration

  5. Do a test run

    Power Automate Subtract from time action test run result

    Test run result – Power Automate Subtract from time

Leave a Comment

Your email address will not be published.