Power Automate addHours() Function

I recently had a task to append a certain number of hours to a specific date or timestamp. I used the Power Automate AddHours() function to achieve that.

This Power Automate tutorial explains everything related to the addHours() function in Power Automate, its syntax, and how to use it.

Also, we will see how to work with addHours() to utcNow and addHours() to a SharePoint Date column with various examples.

Power Automate addHours() Function

addHours() function in Power Automate adds a specified number of hours to a date or timestamp as the other datetime functions like addMinutes(), addSeconds, etc.

This function also allows for formatting date results in the desired format. Additionally, it can accept positive and negative values for the number of hours added.

Power Automate addHours() Function

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

Power Automate addHours() Syntax

Here is the syntax for the addHours() function in Power Automate.

addHours('timestamp', hours, 'format')

Parameters:

  • Timestamp: A mandatory field with date and time in a string format.
  • Hours: It is a required field that can take a positive or negative number of hours to add to the date.
  • Format: It is optional to format the string in a specific format. The default format is [yyyy-MM-ddTHH:mm: ss.fffffffK]. If the format is not valid, then it gives the error message.

The returned value from the Power Automate addHours() function will be a timestamp plus a given number of hours.

Example:

addHours(['2023-12-06'],3)

Where,

  1. ‘2023-12-06’ = Provide the date as per your need.
  2. 3 = Specify the hours that you want to add.

Here, the output will be as ‘2023-12-06T03:00:00.0000000’.

This is the format of the Power Automate addHours() function syntax in a flow.

Power Automate addHours() to utcNow

This example shows how to work with addHours() to utcNow in Power Automate.

Example:

Within this example, we will add specific hours to the current date. So that Today’s date will display along with the time by adding hours to the date.

Let’s say today is “06/12/2023,” and I want to add 10 hours to my current time. Then my result will be 06/12/2023T11:04:35 as shown below. [As my current time is 01:00].

Power Automate addHours() Function

To achieve this, follow the steps below:

Let’s begin with an example of addHours() to Power Automate’s utcNow() function.

1. Navigate to https://make.powerautomate.com to open the Power Automate Home page -> Click + Create -> Select Instant cloud flow -> Provide a flow name & select trigger Manullay trigger a flow -> Tap Create button.

Power Automate addHours() expression in a flow

2. To provide an addHours() expression, take an ‘Initialize variable‘ flow action and set the details of the variable like:

  • Name = Provide the variable name as Add Hours.
  • Type = Select String.
  • Value = Select the field -> Click Expression and write the code below:
addHours(utcNow(),10,'dd/MM/yyyyThh:mm:ss')

Click on OK.

Power Automate addHours() to utcNow

3. Now, add the Compose action to check the output from the addHours() expression.

Inputs: Select the field -> Click Expression and select the Add Hours variable from the dynamic content.

Power Automate addHours()expression to utcNow

4. Now the flow is created. It’s time to Save and run the flow manually.

5. Upon successfully executing the flow, open the ‘Compose‘ flow action to check the addHours() expression output.

Power Automate addHours() Function

This is how to addHours() to utcNow in Power Automate flow.

Power Automate addHours() Negative

To demonstrate the example of Power Automate addHours() negative values, follow the same pattern of steps previously discussed.

Example:

Here, we will add negative hours to the given timestamp or date so that it will subtract the provided hours from the given timestamp.

Let’s take the timestamp as “2023-12-20T15:00:00Z. “ After that, I want to add negative hours (-5) to the timestamp. Then my result will be “20-12-2023T10:00:00,” as shown below. [As it will subtract ‘5‘ hours from the actual given time].

Power Automate add negative hours to date

1. In the ‘Initialized variable‘ flow action, change the expression with negative values in the ‘Value’ section as given below. Below are the details of ‘Initialized variable.’

  • Name = Provide the variable name as Add Hours.
  • Type = Select the variable type as ‘String‘.
  • Value = Select the field -> Click Expression and write the code below.
addHours('2023-12-20T15:00:00Z',-5,'dd-MM-yyyyTHH:mm:ss')

Then, click on OK.

When using negative values in the addHours() expression, the function will output a specific date value, which reflects the subtraction of that number of hours from the original hours.

Power Automate flow addHours() Negative

2. The compose flow action will produce the output using a Power Automate addHours() function, resulting in a date value obtained by subtracting a specified number of hours (5) from the original hours. The result will be [20-12-2023T10:00:00].

Microsoft Power Automate flow addHours() Negative

This is how to add negative hours to the date in a Power Automate flow.

Power Automate addHours() to SharePoint Date

This section will show you about Power Automate addHours() to SharePoint date column values.

Example:

I have a SharePoint list [Task List] with a Date column named Task Deadline. This list has various items along with dates, as shown below.

Power Automate flow addHours() function

I want to add extra hours to this SharePoint Date column using Power Automate. Let’s imagine a date “08/12/2023“, and if we add 5 hours to this date, it will provide the result along with the time as 2023-12-08T05:00:00:0000000.

C:\Users\Chand\Downloads\December Month\Power Automate addHours() to date column in SharePoint.jpg

To achieve it, follow the steps below:

1. Browse make.powerautomate.com in the browser to open the Power Automate Home page. On the Home page, click +Create -> Select Automated cloud flow -> Give flow name and choose the trigger -> Click Create button.

Inside the trigger, provide the below details, as shown in the screenshot.

  • Site Address: Select a site address from the drop-down.
  • List Name: Choose a specific list name from the drop-down.
C:\Users\Chand\Downloads\December Month\addHours() expression to SharePoint date in Power Automate.jpg

2. To proceed, initialize a date column in SharePoint using an ‘Initialize variable‘ flow action. Set the below details of the variable.

  • Name: Give the name for the variable as Task Deadline
  • Type: Select datatype as ‘String’ from drop-down.
  • Value: Select the field -> Click Expression -> Take ‘Task Deadline’ from the dynamic content.
C:\Users\Chand\Downloads\December Month\Power Automate addHours() to SharePoint date.jpg

3. Take the expression of addHours() to date in the ‘Compose‘ flow action.

  • Inputs: Select the field -> Click Expression -> Provide the expression of addHours() as below.

After that, Select OK.

Inputs: addHours(variables('Task Deadline'),5)
C:\Users\Chand\Downloads\December Month\Power Automate addHours() expression.jpg

4. After creating the flow, Save and Test the flow properly. At this point, add or modify an item to the specified SharePoint list. Here, I was modifying the item already present in the SharePoint list.

How to use Power Automate flow addHours() function

5. Then, the outputs of the compose flow action will show the date, adding specific hours to the date as below. The result will add hours to the date value like [2023-12-08T05:00:00.0000000].

C:\Users\Chand\Downloads\December Month\Power Automate addHours() to date column in SharePoint.jpg

This is about the Power Automate addHours() function to calculate and add specified hours to the SharePoint date.

Conclusion

I hope this tutorial has taught you how to use the Power Automate addHours() function. In addition to this, I have covered a few examples of addHours() expressions like:

  • Power Automate addHours() to utcNow
  • Power Automate addHours() negative
  • Power Automate addHours() to SharePoint date

Also, you may like some more Power Automate tutorials: