October 13, 2024

The addDays Function works just like the addSeconds Function and other similar functions. It adds the number of days to a specific date, based on a particular format.

Usage

It follows a simple pattern.

  1. Date
  2. Number of days to add/remove
  3. (Optional) Date Format

Example:

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

will return 

'2019-11-07T10:10:00Z'

Looks quite straightforward, right? Positive numbers add days, and negative excludes 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 Power Apps, there’s no limitation to the date that you can use. You can do things like:

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

and you'll get 

1001-01-09T00:00:00Z

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 seconds, so don’t do any math trying to use the addMinutes Function to add days, for example.
  3. Complementary to the addDays Function, you can also use the addToTime Function. I recommend using the addDays Function because it makes the formula more readable, but the result is the same.

Sources:

Microsoft’s addDays Function Reference

Back to the Power Automate Function Reference.

Photo by Charles 🇵🇭 on Unsplash

Manuel Gomes

I have 18 years of experience in automation, project management, and development. In addition to that, I have been writing for this website for over 3 years now, providing readers with valuable insights and information. I hope my expertise allows me to create compelling, informative content that resonates with the audience.

View all posts by Manuel Gomes →

4 thoughts on “Power Automate: addDays Function

  1. Instead of using a number in the “Number of days to add/remove”, I would like to use a variable. I have tried this and it keeps saying invalid expression. Any workaround is welcome.

    1. Hi,

      It’s possible.

      Here’s the formula:
      addDays('2019-10-28T10:10:00Z', variables('VALUE'),'yyyy-MM-ddTHH:mm:ssZ')

      for the following Power Automate:
      Simple Power Automate with variable example

      Is this what you need?

  2. Hi! I just want to use the Submitted Date from a list / Form and add a day to it for my Outlook Calendar event start time. How do I do this? Here’s what I have –

    Trigger: When an Item is created of Modified from a Sharepoint List,

    Action: Create an Event

    Start time: ???????????? – needs to show a day later from my Submitted Time in the list

    Please help. I’m a newbie and trying to create efficiency at work. Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

Mastodon