Do you need to add 1 year to a date value in your flow?
This functionality is useful in a variety of scenarios, such as setting email reminders, adjusting deadlines, or calculating due dates.
Perhaps you are working with a renewal date that will be exactly one year from the current date. This will require that you’re able to add 1 year to the current date when the flow runs.
In this article, you’ll learn how to add one year to any date or date timestamp in Power Automate using the addToTime function.
- Power Automate provides the addToTime function for working with dates and time.
- The syntax of the addToTime function allows for the addition of specific time units such as years.
Syntax of the addToTime Function
In Power Automate, you can use the
addToTime expression to add a specific interval of time to a given timestamp. This is particularly useful when you want to add one year to a date, as it takes into account leap years.
To use the addToTime function, follow this general syntax:
addToTime('<timestamp>', <interval>, '<timeUnit>', '<format>?')
<timestamp>is the original date and time value you want to modify. It should be a string in the format of a date such as
'yyyy-MM-dd'or a date timestamp such as
<interval>is the numeric value representing the amount of time you want to add.
<timeUnit>is a string indicating the unit of time you want to add, such as
<format>is an optional string to specify the desired format for the output date and time. For example, if you only want to return the date part of a date timestamp, then this would be
addToTime('<timestamp>', 1, 'Year', '<format>?')
You can use the above expression to add one year to a date value.
Adding One Year to a Date with the addToTime Function
In Power Automate, you can easily add one year to a date using the addToTime function.
This function allows you to manipulate date values in a variety of ways, including adding or subtracting designated time units like seconds, minutes, hours, days, weeks, months, and years.
addToTime(outputs('Date'), 1, 'Year', 'yyyy-MM-dd')
In this example, there is a date value in a Compose action named Date. The above expression will reference the date from the Compose action and add exactly 1 year to the date value.
The function then returns the new incremented date in the yyyy-MM-dd format
📝 Note: The addToTime function is versatile, and you can use it to add or subtract any number of years or other time units to your date or time value. Just modify the
<timeUnit> parameters accordingly to fit your needs.
With the addToTime function and the right parameters, adding one year or any other time unit to a specific date and time value is easy!
addToTime('2024-02-29', 1, 'Year', 'yyyy-MM-dd')
This function will even take care of leap-year scenarios. For example, adding 1 year to the date 2024-02-29 with the above expression will result in the date 2025-02-28.
Adding one year to a date is a useful technique for various scenarios such as calculating renewal dates during flow execution.
Using the provided addToTime function, you can manipulate date and time values to satisfy your specific requirements.
I hope this post has helped you to manipulate the dates in your flows as needed. Let me know in the comments!