Move weekend due date when creating Planner tasks in Power Automate
Posted On August 1, 2021
“How can I tell my Power Automate flow to create Planner tasks with due date only on working days, to skip weekend and move it to Monday instead?”
When you create Planner tasks automatically with Power Automate, you might automatically calculate also their due date. Take today’s date, add the desired task duration, and get the task due date. But here comes a small complication. If you created tasks manually, you wouldn’t select Saturday or Sunday as the due date. You’d probably move the due date to the next working day: Monday. But Power Automate won’t do that, unless you add the logic by yourself. And this article will show you how.
The main expression for this solution is the dayOfWeek(…) expression. When you enter a date as a parameter, it’ll return a number from 0 to 6. Using today’s date, it’ll work as below:
dayOfWeek(utcNow()) will return 0 on Sunday
1 on Monday
6 on Saturday
The same logic can be used on any date. It can be a calculated date or a date from other source, e.g. a date of a task imported from an Excel file. Following the Excel example, let’s take the basic expression: if the date cell in Excel is not empty, you use the date. The date must be in the ISO 8601 format.
Now it’s time to do the same for Saturday. Extending the expression above, if the condition is false (it’s not Sunday), let’s check if it’s Saturday. If it’s Saturday, you must add 2 days to turn it into Monday.
The solution above is not limited to skipping weekend when creating Planner tasks with Power Automate. With the dayOfWeek(…) expression you can build many interesting solutions, e.g. to run a flow only on specific day in a specific week in a month. Just remember that the week starts with 0 on Sunday and ends with 6 on Saturday.
But that was only one part of the solution, the other one is the if(…) expression. It’s a powerful expression which can help you save a lot of flow actions. As you can see in the final expression, it’s 3 IFs deep, and you could go much deeper if needed. You could achieve the same functionality with a variable and 3 levels of ‘Conditions’, or you can have 1 composed expression…