Power Automate subtractFromTime() Function

Have you ever used the subtractFromTime() function in Power Automate? Then, read this tutorial to understand the Power Automate subtractFromTime() function.

This tutorial will describe the subtractFromTime() function in Power Automate and how to use its syntax. Also, we will discuss how to use the Power Automate subtractFromTime() function with various examples.

subtractFromTime() function in Power Automate is useful for subtracting specific time units to a given timestamp, like seconds, minutes, hours, days, weeks, months, or years based on the unique needs.

Power Automate subtractFromTime() Function

Power Automate subtractFromTime() is designed to subtract a specific unit of time from a given timestamp. This function enables users to subtract various time units, including seconds, minutes, hours, days, weeks, months, or years, based on their requirements.

The output of the “subtractFromTime()” function is a timestamp that is reduced by the specified number of time units.

This is the overview of the Power Automate subtractFromTime() function.

Power Automate subtractFromTime() Syntax

Here’s the syntax for the Power Automate subtractFromTimeTime() function:

subtractFromTime('timestamp', interval, 'time unit', 'format')

Parameters:

  • Timestamp: It is a required field where a user can add time to the timestamp.
  • Interval: It is in the form of an integer where a particular number of time units are added.
  • Time Unit: It represents the unit of time that can be used with intervals like Second, Minute, Hour, Day, Week, Month, and Year.
  • Format: It is an optional field where a user can provide a custom timestamp format. If not provided, it will take the default format[yyyy-MM-ddTHH:mm: ss.fffffffK].

Example:

For example, I will subtract one-day time unit from the date.

subtractFromTime('2024-01-02T00:00:00Z', 1, 'Day')
  1. 2024-01-02T00:00:00Z = Give the timestamp as per your requirement.
  2. 1 = Specify a particular interval of time unit.
  3. Day = Provide the time unit like Second, Minute, Hour, Day, Week, Month, and Year per your need.

Here will be the output as 2024-01-01T00:00:00.0000000Z.

This is the overview of the Power Automate subtractFromTime() function syntax.

Power Automate subtractFromTime() in Second

Using Power Automate flow, I will illustrate an example of Power Automate subtractFromTime() in seconds.

Example:

I will subtract a specific number of seconds from the provided timestamp. So, the outcome will display a date and time with the remaining seconds.

Let’s take a date as “2024-01-02“. From this date, I am required to subtract 20 seconds. Then, my result will be 2024-01-01T23:59:40, as shown below.

Power Automate subtractFromTime() Function

So, Let’s dive into the below steps!

1. Navigate to make.powerautomate.com in the browser to open the Power Automate Home page -> Tap on +Create -> Select Instant cloud flow -> Take Manually trigger a flow and enter a flow name -> Click Create.

  • Open the trigger -> Click Add an input -> Select Date.
subtractFromTime() Function in Power Automate

2. Add an Initialize variable flow action under the flow trigger to give the subtractFromTime() expression in a flow.

Set the parameters of the initialized variable.

  • Name: Enter the variable name manually as Date.
  • Type: Select String datatype.
  • Value: Take the value that is given in the code below.
subtractFromTime(triggerBody()['date'],20,'Second','yyyy-MM-ddTHH:mm;ss')

Click OK.

Power Automate subtractFromTime() expression

3. To view the output of the Power Automate subtractFromTime() function, we can use the Compose data operation. Add the Compose data operation and give the value in the ‘Inputs’ section.

Inputs: Click the field -> Take the Date variable from dynamic content.

subtractFromTime() expression in Power Automate

4. After creating the flow, Save and Test the flow manually. In the Run flow window, pick the triggered date the unit needs to be added.

  • The triggered date is 2024-01-02.
subtractFromTime() function in Power Automate

5. Now the flow runs successfully, it will notify a message as ‘Your flow ran successfully. The outputs of compose will display the returns of the subtractFromTime() expression as below.

  • The output is 2024-01-01T23:59:40.
Power Automate subtractFromTime() in Second

This is how to remove seconds from the date and time using the Power Automate subtractFromTime() function.

Power Automate subtractFromTime() in Day

Going deep into the Power Automate subtractFromTime() function, let’s consider subtracting days from the time stamp.

Follow the same steps that are mentioned in the above example:

  • Add a manual trigger flow to take the input as ‘Date.’
  • Initialize trigger date variable.
  • Provide subtractFromTime() expression in the Compose flow action.

Example:

This example involves subtracting a specific number of days from a particular timestamp. For example, if we begin with a timestamp of “2023-01-05” and intend to subtract 2 days, the resulting timestamp will be “2023-01-03,” as shown below.

How to use Power Automate subtractFromTime() function

Follow the below given steps:

1. In the ‘Inputs’ of the compose flow action, give the expression to subtract days from the timestamp.

Inputs: Select the field -> Click Expression -> Add the expression given below.

subtractFromTime(triggerBody()['date'],2,'Day','yyyy-MM-dd')

After that, Click OK.

Power Automate subtractFromTime() in Day

2. Once the flow has been saved, select the desired date for the unit to be added in the “Run flow” window. Then, click Run flow.

  • The triggered date is 2024-01-05.
Microsoft Power Automate subtractFromTime() expression

4. The image below illustrates the subtractFromTime() function results, which removes two days from the provided timestamp.

  • The result will be 2023-01-03.
How to use Power Automate subtractFromTime()expression

This is about the Power Automate subtractFromTime() function to subtract days from a timestamp.

Power Automate subtractFromTime() in Month

Using a SharePoint list, let’s check out an example of the Power Automate subtractFromTime() function.

Example

I have taken a SharePoint list named [Hazard Checklist – Workplace] with a date column as Date. This list has various items along with dates, as shown below:

Microsoft Power Automate subtractFromTime() function

My requirement is to subtract one month from the SharePoint date column, i.e., Date using Power Automate.

For example, if we take “2024-03-01,” my result displayed will be 2024-02-01. It will subtract one month from the given timestamp.

subtractFromTime() function format in Power Automate

To work with this, follow the below-given steps:

1. Log into Power Automate with your Microsoft credentials -> In the Power Automate Home page, tap +Create -> Select Automated cloud flow -> Provide a flow name & select trigger When an item is created or modified -> Tap the Create button.

  • Site Address: Select a SharePoint site address from the drop-down.
  • List Name: Choose a specific SharePoint list name from the drop-down.
Power Automate subtractFromTime() function syntax

2. To initialize the “Date” column, utilize the “Initialize Variable” flow action and set the relevant parameters.

  • Name: Provide the name manually as the Date.
  • Type: Select the variable type as String.
  • Value: Select the field -> Take Date from the dynamic content of the SharePoint list.
Power Automate subtractFromTime() from SharePoint date

3. Now include the subtractFromTime() expression and the value from the initialized variable into the Compose flow action.

Ensure to give details in the inputs as below.

Select a field -> Click Expression -> Insert below expression.

subtractFromTime(variables('Date'),1,'Month','yyyy-MM-dd')

After giving the expression, Click OK.

Power Automate subtractFromTime() in Month

4. After creating the flow, save it and test it manually. Here, I will modify the existing SharePoint list item as below.

How to get subtractFromTime() in Month using Power Automate

5. When the flow runs successfully, it will display the output in the compose flow action. The return value from the subtractFromTime() expression will be like 2024-02-01.

Microsoft Power Automate subtractFromTime() expression

This is how to subtract a month from the SharePoint list date column using the Power Automate subtractFromTime() function.

Conclusion

I trust this tutorial has comprehensively understood how to effectively utilize the Power Automate subtractFromTime() function. Besides the syntax, I’ve also included various examples of how this function can be employed in Power Automate, as mentioned below.

  • Power Automate subtractFromTime() in second
  • Power Automate subtractFromTime() in day
  • Power Automate subtractFromTime() in month

Also, you may like some more Power Automate function tutorials: