In this post, we will learn what is the Power Automate add days to date function ? and how to use How To Use addDays In Power Automate? So we will discuss the following topics in this post:
- Power Automate add days syntax.
- Power Automate add days format.
- Power Automate add days to utcnow “Add days to the current date in the Power Automate flow”.
- Power Automate add days to date.
- Power Automate add days exclude weekends.
- Power Automate add days to due date.
- Power Automate add days to created date
Power Automate add days Function
- The add days Power Automate function is one of the Date and time functions to work with dates and times.
- addDays adds the number of days to a specific date based on a particular format ” Add days to a timestamp.”
- The default format of the timestamp is(yyyy-MM-ddTHH:mm:ss.fffffffK),You can define a single format specifier or a custom format pattern (for example: “yyyy-MM-dd”) So be sure to define your favorite format.
- The addDays Function works just like the addHours, addSeconds, addMinutes Function and other similar functions.
Power Automate add days syntax.
addDays('<timestamp>', <days>, '<format>'?)
- addDays: the function name to add days to timestamp.
- <timestamp>: The string that contains the timestamp “DateTime in string format”, it is required and of type String.
- <days>: the number of days that will be added to the timestamp ” positive or negative“, it is Integer and Required
- <format>: A numeric format string that convert the DateTime into a specified format, it is optional ,The default value is “yyyy-MM-ddTHH:mm:ss:fffffffK”,but be sure to define your format, as the date provided may not be stored in the same format and will return either wrong times or errors.
Return value: it returns the timestamp plus the specified number of days “String of the updated-timestamp“
Power Automate add days to utcnow
One of the most common scenarios in Power Automate is to perform some operations on the current date. So, Add Days is one of its kind of function that works on the current date to perform certain actions such as get all changes of a SharePoint list in specific period, sending an email to alert or provide information, delay a flow to certain time of item created and so on.
Example # 1
In the following example, the user can save a travel request as draft for submitting later,
If it is not submitted within 1 month or 30 days, then automatically treat it as a Cancelled Request. So we will use the Power Automate add days to utcNow and add 30 days to utcNow
addDays(utcNow(),30)
Example # 2
Power Automate add days negative
In this example we will get all changes in the list for last 2 days .e we will use this formula in the Filter Query to fitter the items by created and modified that is greater or equal to utcNow()-2
Created ge '@{addDays(utcNow(),-2)}' and Modified ge '@{addDays(utcNow(),-2)}'
“>=” is “ge”
Power Automate add days format
The output from the previous example is in the format ‘YYYY-MM-dd’ this is the default format of the add days function
Created ge '2022-10-19T10:12:20.9814338Z' and Modified ge '2022-10-19T10:12:20.9814338Z'
you can change format to your desired format, for example MM-dd-yyyy , you can use the formatDateTime() function
formatDateTime(variables('VariableName'),'MM-dd-yyyy')
power automate add days to date
Example # 1 Power Automate add 5 day to date
you can use the power automate addDays function to add days to date , in the following example we will add 5 days to a specific date that stored in the variable Date.
addDays(variables('Date'),5)
Example # 2 Power Automate add one day to date
Power Automate add one day to date and get the result in the dd-MM-yyyy format.
addDays(variables('Date'),1,'dd-MM-yyyy')
Example # 3 Power Automate add days to start date
In this example we will get the end date that will be after 10 days from the travel start date
addDays(triggerOutputs()?['body/@{outputs('Get_item')?['body/TravelStartDate']}'],10,'yyyy-MM-dd')
the output will be as following
addDays(triggerOutputs()?['body/2022-10-20'],10,'yyyy-MM-dd')
Example #4 Power Automate add days to created date
In the beloww example we will add 5 days to the created date of the SharePoint list item
addDays(item()?['Created'],5,'dd-MM-yyyy')
Example #5 Power Automate add 365 days to date
Here we will see how to add 365 days to the given date using Power Automate.
addDays(variables('Date'),365,'dd-MM-yyyy')
Power Automate add days exclude weekends
You can use addDays to add nomber of days to specific date or to the current date excluding weekends, in the following example we will add 1 day to utcNow ” the current date”, excluding Weekends.
the following code will check – if day of week is 5 (friday) then add 3 day and if day of week is 6 (saturday) then add 2 days else add 1 day
if( equals(dayOfWeek(addDays(utcNow(),1)),'5'),addDays(utcNow(),3),if( equals(dayOfWeek(addDays(utcNow(),1)),'6'),addDays(utcNow(),2),addDays(utcNow(),1)))
Conclusion
In conclusion, we have learned how to use add days function and covered these topics
- Power Automate add days syntax.
- Power Automate add days format.
- Power Automate add days to utcnow “Add days to the current date in the Power Automate flow”.
- Power Automate add days to date.
- Power Automate add days exclude weekends.
- Power Automate add days to due date.
- Power Automate add days to created date
- Power Automate add days to start date
- Power Automate add 365 days to date
- Add 2 days to date in power automate
- power automate add days exclude weekends
- power automate add days negetive
and learned how to format date in Power Automate
See Also
- How to use Power Automate?
- How to use Date function in DAX Power BI?
- Power Platform and DevOps-Deploy solutions between environments
Join us
- Subscribe to Power Platform Geeks.
- Register to Saudi Arabia Power Platform User Group.
Need Help
- Have a related question? Please ask it at deBUG.to Community.