Skip to content

Subtract from a date

Power Automate Desktop has an action called “Subtract dates,” but what it actually does is convert the difference between two datetime variables into a unit of your choice, so you can’t use it to go back a specified period from a given date.

This article explains how to subtract days, months, or years from a date you have retrieved (that is, how to go back in time).

The action used here is called “Add to datetime.”

Even though it says “add,” you can subtract by adding a negative value.

There’s also an action called “Subtract dates,” but strictly speaking, it gets the difference between two datetimes in seconds, minutes, hours, or days.

Details of the “Add to datetime” action

Section titled “Details of the “Add to datetime” action”

The action has the following parameters.

Parameter Value
Datetime The base datetime for the addition (such as a Datetime variable)
Add The amount to add (the number of years if you choose years in “Time unit”)
Time unit The unit to add (seconds, minutes, hours, days, months, or years)

action

As a sample, I prepared a flow that gets the current date and calculates the date 10 days before it. The last line uses the “Subtract dates” action to find the difference between the two datetimes (10 days).

Copy the following code and paste it into the Power Automate Desktop flow designer to add the actions.

DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime=> CurrentDateTime
DateTime.Add DateTime: CurrentDateTime TimeToAdd: -10 TimeUnit: DateTime.TimeUnit.Days ResultedDate=> ResultedDate
DateTime.Subtract FromDate: CurrentDateTime SubstractDate: ResultedDate TimeUnit: DateTime.DifferenceTimeUnit.Days TimeDifference=> TimeDifference
  1. In “Search actions,” type “Add to datetime.”

  2. Set the parameters as follows.

    Parameter Value
    Datetime %CurrentDateTime%
    Add -10
    Time unit Days
  3. When you run the flow, the datetime 10 days before the specified date is stored in a new variable (default: ResultedDate).

This action doesn’t throw any exceptions.