Do you need to test if a date is a business day in your flow?
Power Automate is a business tool for automating processes. As such it’s likely any deadlines, task assignments, and operational schedule dates will need to be business days.
You can test if your dates fall on a business day with a simple function in Power Automate.
This article will show you how to check if a date is a business day using the dayOfWeek function and a Condition action.
DayOfWeek Function Syntax
To check if a date is on a business day in Power Automate, you can use the dayOfWeek function.
This function returns an integer number representing the day of the week.
<date>is the date and timestamp for which you want to return the weekday number.
This function will return the following values.
0if the date is a Sunday
1if the date is a Monday
2if the date is a Tuesday
3if the date is a Wednesday
4if the date is a Thursday
5if the date is a Friday
6if the date is a Saturday
If you want to know if a given date is on a business day or not, you can compare the result of the dayOfWeek function to the desired range of business days. Typically, business days are Mondays to Fridays, which corresponds to integers 1 to 5.
If the condition is true, then the date is a business day. Otherwise, it’s a weekend.
Use Condition to Test dayOfWeek Function Results
This section will explore how to set up a Condition action to determine if the date is a business day and will suppose the dayOfWeek function has already been called with your date.
In this example, the date to test is inside a Compose action, and the expression
dayOfWeek(outputs('Compose')) calculates the day of the week for this date.
This result is then referenced in the Condition action as
Condition Function to Test dayOfWeek Results
The dayOfWeek function returns 0 for Sunday and 6 for Saturday. This means to test if the date is not a business day and instead falls on the weekend, you only have to test if the value is 0 or 6.
- Add the Condition action to your flow.
- Click the Add button and select Add row in the Condition action to allow 2 conditions. One will test fo a 0 and the other for a 6.
- Select the Or option for the conditions. This means the If yes branch will run if either of the conditions are true.
- Place the dynamic content for dayOfWeek results on the left side of condition 1, select the is equal to option for the condition, then enter
6on the right side.
- Place the dynamic content for dayOfWeek results on the left side of condition 2, select the is equal to option for the condition, then enter
0on the right side.
- Place any actions you wish to execute if the date is found to be a business day in the If no branch of the condition.
The If no branch will run whenever the date is a business day..
Checking if a date falls on a business day can be achieved using built-in functions and actions.
By using the dayOfWeek function, you can determine the day of the week for a given date and test if this is a weekend or not.
This will return a numerical value from 0 (Sunday) to 6 (Saturday) representing the day of the week. With this information, you can ascertain whether the date is a business day or not.
Then you can create a condition that checks if the value is either 0 or 6, which corresponds to a weekend.
Have you needed to test your dates if they fall on a business day? Let me know in the comments!