Power Automate: addSeconds Function

Power Automate: addSeconds Function

by: Manuel ⏱️ 📖 2 min read 💬 0
I’ve used the addSeconds Function in previous posts but never spent time to explain it adequately. This function adds the number of seconds to a specific date, based on a particular format.

Usage

It follows a simple pattern.
  1. Date
  2. Number of seconds to add/remove
  3. (Optional) Date Format
Example:
addSeconds('2019-10-28T10:10:00Z', 10,'yyyy-MM-ddTHH:mm:ssZ')

will return 

'2019-10-28T10:10:10Z'
Looks quite straightforward, right? Positive numbers add seconds, and negative exclude seconds. Please be aware that, in 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:
addSeconds('1000-12-30T00:00:00Z',10,'yyyy-MM-ddTHH:mm:ssZ')

and you'll get 

1000-12-30T00:00:10Z
They behave like you’re expecting.

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 stored in the same format, and will return either wrong times or 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. There are analogous functions for hours, minutes, and days, so don’t do any math trying to use the addSeconds Function to add days, for example.
  3. Complementary to addSeconds Function you can also use the addToTime Function. I recommend using addSeconds Function because it makes the formula more readable, but the result is the same.

Sources:

Microsoft’s addSeconds Function Reference   Back to the Power Automate Function Reference Featured Image by Agê Barros on Unsplash

Comments

💬

No comments yet

Be the first to share your thoughts on this article!

Leave a Comment

Comments are moderated before appearing 5000 chars left
Replying to