cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
sammybridge
Helper IV
Helper IV

Add on working days to Today()

I am trying to, on the push of a button, set a date which is Today() + X number of working days. I cannot figure out how to get this working to account for every eventuality. I am going to be creating a number of tasks (list items) at one time using Patch and all of them will have a different Due Date (Today() + X days).

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
timl
Super User III
Super User III

Hi @sammybridge 

In the OnSelect property your button, you can add the following code:

Set(varDaysToAdd,3);
Set(varResult, DateAdd(Today(),
Value(varDaysToAdd) + 
RoundDown(Value(varDaysToAdd) / 5, 0)*2+
Switch(Weekday(Today()),5,If(Mod( Value(varDaysToAdd) , 5)>0,2,0),
                                         4,If(Mod( Value(varDaysToAdd) , 5)>1,2,0),
                                         3,If(Mod( Value(varDaysToAdd) , 5)>2,2,0),
                                         2,If(Mod( Value(varDaysToAdd) , 5)>3,2,0),
                                         1,If(Mod( Value(varDaysToAdd) , 5)>4,2,0))
)
)

The variable varDays defines the number of days to add (3 in this example).
The set statement stores the result of the calculation in the variable varResult.

This formula is based on @Siennas logic to exclude to exclude Saturdays & Sundays, so the credit goes to him. 

https://powerusers.microsoft.com/t5/Building-Power-Apps-Formerly/Adding-working-days-and-hours-to-a-... 

 

View solution in original post

2 REPLIES 2
chrisog
Responsive Resident
Responsive Resident

Hi @sammybridge,

 

It may be that the DateAdd() function could work for you. The syntax is DateAdd(date, number_of_units, unit)

 

So in your instance, if you can pre-determine somewhere in your app for the amount of days to add for each list item, you can simply use DateAdd(Today(), number_of_days, Days), where number_of_days refers to the value assigned to this list item.

timl
Super User III
Super User III

Hi @sammybridge 

In the OnSelect property your button, you can add the following code:

Set(varDaysToAdd,3);
Set(varResult, DateAdd(Today(),
Value(varDaysToAdd) + 
RoundDown(Value(varDaysToAdd) / 5, 0)*2+
Switch(Weekday(Today()),5,If(Mod( Value(varDaysToAdd) , 5)>0,2,0),
                                         4,If(Mod( Value(varDaysToAdd) , 5)>1,2,0),
                                         3,If(Mod( Value(varDaysToAdd) , 5)>2,2,0),
                                         2,If(Mod( Value(varDaysToAdd) , 5)>3,2,0),
                                         1,If(Mod( Value(varDaysToAdd) , 5)>4,2,0))
)
)

The variable varDays defines the number of days to add (3 in this example).
The set statement stores the result of the calculation in the variable varResult.

This formula is based on @Siennas logic to exclude to exclude Saturdays & Sundays, so the credit goes to him. 

https://powerusers.microsoft.com/t5/Building-Power-Apps-Formerly/Adding-working-days-and-hours-to-a-... 

 

View solution in original post

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (1,144)