2 Ways to Add Days to a Date in Power Automate

Do you need to add days to a date in Power Automate?

A common scenario that users often encounter is the need to add or manipulate dates within a flow. In particular, adding days to a specific date can be essential for tasks such as scheduling reminders or calculating deadlines.

Power Automate has a built-in function for this, which allows you to add a specified number of days to a given date.

This post will show you how to use the addDays or addToTime function to add any number of days to a date in your flow.

Adding Days to Dates with the addDays Function

The addDays function allows you to add a specified number of days to a date.

addDays(<timestamp>, <days>, <format>?)
  • <timestamp> is the date to which you want to add days. This can be a date string or a dynamic value that represents a date.
  • <days> is the number of days you want to add to the <timestamp>. This can be a number or a dynamic value that represents a number.
  • <format> (optional) is the format of the resulting date. This can be a string that represents a format specifier or a custom format pattern.
addDays(outputs('Date'), 7, 'yyyy-MM-dd')

For example, if you want to add 7 days to a date string in a compose action named Date and return the result in the format yyyy-MM-dd, you can use the above expression. In this example, the result will be 2023-08-02.

addDays(outputs('Date'), -7, 'yyyy-MM-dd')

The addDays function can also be used with negative numbers to subtract a number of days from the date.

The above expression will subtract 7 days from the date and would return 2023-07-19 in this example.

Adding Days to Dates with the addToTime Function

The same result of adding days to a date can also be achieved with the addToTime function.

This is a more flexible function that will allow you to add different time intervals to your date such as seconds, minutes, hours, days, weeks, months, or years.

addToTime('<timestamp>', <interval>, '<timeUnit>', '<format>'?)
  • <timestamp> is the date and time to which you want to add an interval. This can be a date and time string or a dynamic value that represents a date and time.
  • <interval> is the amount of time you want to add to the <timestamp>. This can be a number or a dynamic value that represents a number.
  • <timeUnit> is the unit of time you want to add to the <timestamp>. This can be one of the following: year, month, week, day, hour, minute, or second.
  • <format> (optional) is the format of the resulting date and time. This can be a string that represents a format specifier or a custom format pattern.
addToTime(outputs('Date'), 5, 'day', 'yyyy-MM-dd')

For example, the above expression will add 5 days to the date from the compose action named Date. In this example, the result will be 2023-07-31.

Conclusions

Adding days to a date can be a helpful technique when working with deadlines, reminders, or calculating specific dates. To achieve this, you can use the addDays function.

For adding days you can either use the addDays or addToTime functions. These both will allow you to subtract days from a date as well by specifying a negative number of days to add.

The addToTime function is a more flexible version of the addDays function and can be used to add or subtract other time intervals.

Have you needed to add or subtract days from your dates? How did you do this? Let me know in the comments!

About the Author

John MacDougall

John MacDougall

John is a Microsoft MVP and freelance consultant and trainer specializing in Excel, Power BI, Power Automate, Power Apps and SharePoint. You can find other interesting articles from John on his blog or YouTube channel.

Related Articles

Comments

0 Comments

Get the Latest Tech Tips

Write For Us

Are you a tech enthusiast with a talent for writing great content? Come write for us!

Follow Us

Follow us on social media to stay up to date with the latest in tech!