Power Automate Subtract Minutes: How-To Guide
To subtract minutes from a time in Power Automate, use the subtractFromTime() expression in a Compose or variable action. This function takes a timestamp, a number, and the unit (“Minute”), and returns the new timestamp. For example, subtractFromTime(utcNow(), 30, 'Minute') gives you the time 30 minutes before the current moment.
Understanding the subtractFromTime Function
Power Automate (formerly Microsoft Flow) handles date and time arithmetic through expressions, primarily using the subtractFromTime function. This is part of the workflow definition language (WDL) that underpins Power Automate and Azure Logic Apps. The function signature is:
subtractFromTime('timestamp', 'subtractValue', 'unit', 'format'?)
- timestamp: A string representing the starting date/time. Common sources are
utcNow()for the current time, or a dynamic content token from a trigger or action (e.g., a SharePoint date column). - subtractValue: An integer (or a string that can be converted to an integer) representing how many units to subtract. Use a positive number to subtract; negative numbers add.
- unit: A string indicating the time unit: “Second”, “Minute”, “Hour”, “Day”, “Week”, “Month”, or “Year”. For subtracting minutes, you use “Minute”.
- format (optional): A format string for the output, like “yyyy-MM-dd’T’HH:mm:ss” or “MM/dd/yyyy hh:mm tt”. If omitted, the default format is ISO 8601 (e.g., 2025-04-10T14:30:00.0000000Z).
How to Subtract Minutes in a Flow
There are several ways to apply this, depending on what you need the result for.
- Compose action: Add a “Compose” action, and in the “Inputs” field, enter the expression. This is the simplest way to test or store the result for later use.
- Set variable: If you have a variable of type String, use the “Set variable” action and put the expression in the “Value” field.
- Inline in a condition: You can use the expression directly in a Condition’s expression box, e.g.,
lessOrEquals(utcNow(), subtractFromTime(triggerOutputs()?['startTime'], 15, 'Minute')). - In a Send an email action: Use the expression in the body or subject to display the calculated time.
Always ensure the expression is entered in the expression editor (the “fx” tab), not the dynamic content editor. If you type it directly into a text field, it will be treated as a literal string.
Choosing the Right Function: subtractFromTime vs. addToTime
You might wonder whether to use subtractFromTime or addToTime. The answer is simple: subtractFromTime is for subtracting, addToTime is for adding. However, you can achieve subtraction with addToTime by passing a negative number: addToTime(utcNow(), -30, 'Minute'). Both work, but using subtractFromTime is more readable and less error-prone.
Common Problems and How to Fix Them
- Expression not recognized: If you see the expression as plain text, you likely typed it in the wrong editor. Use the “fx” (expression) tab in the action’s input field.
- Invalid template language or processing of ‘…’ failed: This usually means the timestamp is not in a valid format. Ensure the timestamp is a string like “2025-04-10T14:30:00Z” or a dynamic content token that represents a date/time. If you’re using a variable, make sure it’s a string.
- Timezone issues:
utcNow()returns UTC time. If you need the local time, useconvertFromUtc()orconvertTimeZone()after subtracting. For example:convertFromUtc(subtractFromTime(utcNow(), 30, 'Minute'), 'Eastern Standard Time', 'yyyy-MM-dd HH:mm'). - Subtracting from a date-only field: If your source is a date-only (e.g., “2025-04-10”), you may need to append a time component:
subtractFromTime(concat('2025-04-10T00:00:00Z'), 30, 'Minute').
Formatting the Output
The default output of subtractFromTime is a long ISO 8601 string with timezone offset (e.g., 2025-04-10T14:30:00.0000000Z). Often you’ll want a more readable format. Use the optional format parameter:
subtractFromTime(utcNow(), 45, 'Minute', 'yyyy-MM-dd HH:mm')
This returns something like “2025-04-10 14:15”. Common format specifiers include:
yyyy– four-digit yearMM– two-digit monthdd– two-digit dayHH– hour in 24-hour formatmm– minutesss– secondstt– AM/PM (use withhh)
Alternatives: Using ticks and addSeconds
For very precise arithmetic, you can work with ticks (100-nanosecond intervals since 0001-01-01). The expression ticks('timestamp') converts a timestamp to a tick count. Then you can subtract the number of ticks in a minute (600,000,000 ticks per minute) and convert back using addToTime or formatDateTime. This is rarely needed, but useful for complex calculations or when dealing with large numbers of time units.
Another alternative is addSeconds, addMinutes, etc., but these are not native Power Automate functions. You would use addToTime with the unit “Second” and multiply the minutes by 60: addToTime(utcNow(), -30*60, 'Second'). This works but is less readable.
Frequently Asked Questions
Can I subtract minutes from a date stored in a SharePoint column?
Yes. Use the dynamic content token for that column as the timestamp. For example, if the column is called “StartTime”, the expression would be subtractFromTime(triggerOutputs()?['body/StartTime'], 15, 'Minute'). Ensure the column is of type Date and Time, not just Date.
What is the difference between subtractFromTime and sub in Power Automate?
sub is for subtracting numbers, not dates. It takes two numbers and returns their difference. To subtract time, you must use subtractFromTime or addToTime with a negative value.
How do I subtract minutes from the current time and get the result in a specific timezone?
Use convertTimeZone after subtracting. For example: convertTimeZone(subtractFromTime(utcNow(), 30, 'Minute'), 'UTC', 'Pacific Standard Time'). Or use convertFromUtc if your source is UTC.
Why does my expression return an error when I use a variable?
Make sure the variable is of type String and contains a valid timestamp. If it’s a variable of type Float or Integer, convert it to string first using string(variables('myVar')). Also, check that the variable is initialized before the action that uses it.
Can I subtract minutes from a time that is in a different format like “14:30”?
Power Automate expects a full timestamp, not just time. You can combine the time with a date: subtractFromTime(concat('2025-04-10T', '14:30'), 10, 'Minute'). This treats the time as part of the date. Alternatively, parse the time into a timestamp using parseDateTime() if needed.
Is there a limit to how many minutes I can subtract?
No practical limit. The function handles large numbers, but be aware of overflow if you subtract an enormous number of minutes (e.g., millions) – the result may go outside the valid date range (year 0001 to 9999). For normal use, it’s fine.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.