Power Automate provides functions to add time-based on each of the units. For example, you can use the addSeconds Function to add only seconds, but the addToTime Function can provide a lot more flexibility since you define the unit that you want to add.

Usage

It follows a simple pattern.

  1. Date
  2. Number to add/remove
  3. Time unit to add
  4. (Optional) Date Format

Example:

addToTime('2019-10-28T10:10:00Z',10,'Second','yyyy-MM-ddTHH:mm:ssZ')

will return 

'2019-10-28T10:10:10Z'

Looks quite straightforward, right? Positive numbers add seconds, and negative exclude them.

Please be aware that the reference material, Microsoft names objects like ‘2019-10-28T10:10:00Z’ as timestamps. I prefer calling them “Date” to avoid confusion with the UNIX timestamp, commonly used in APIs, to represent the number of seconds elapsed since Jan 01, 1970 (UTC).

Limitations

Contrary to SharePoint and PowerApps, there’s no limitation to the date that you can use. You can do things like:

addToTime('1000-12-30T00:00:00Z',10,'Year','yyyy-MM-ddTHH:mm:ssZ')

and you'll get 

1010-12-30T00:00:00Z

Dates behave like you’re expecting them.

Recommendations:

  1. Always include the format, even if the value is optional. The default value is “yyyy-MM-ddTHH:mm:ss:fffffffK,” but the date provided may not be in the same format returned or even trigger errors. You can define a single format specifier (for example, “o”) or a custom format pattern (for example, “yyyy-MM-dd”), so pick your favorite, but be sure to define it.
  2. I prefer to use individual functions instead of this function. For example, I prefer using the addSeconds Function since it makes the formula quite clear and shorter. It’s a matter of preference since the result will be the same.

Sources:

Microsoft’s addToTime Function Reference

Back to the Power Automate Function Reference

Featured Image by NeONBRAND on Unsplash

Manuel Gomes

I'm a Project Manager with experience in large projects and companies. I've worked in the past for companies like Bayer, Sybase (now SAP) and I'm currently working for Pestana Hotel Group.

View all posts by Manuel Gomes →

Leave a Reply

%d bloggers like this: