cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
abieba
Level: Powered On

exclude weekeneds in date calculations

Hello Guys,

i am trying to exclude weekends 4rom my dat calculations 

i saw and try this

RoundDown(DateDiff(StartDate.SelectedDate, EndDate.SelectedDate, Days) / 7, 0) * 5 +
Mod(5 + Weekday(EndDate.SelectedDate) - Weekday(StartDate.SelectedDate), 5)

but was not working well

Please help. 

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: exclude weekeneds in date calculations

@abieba 

Something strange is happening with your formula when I tested in my own app.  Please try my code instead.  It seems to correct the problem we are having.

 

RoundDown(DateDiff(TravelValue.SelectedDate, ReturnValue.SelectedDate, Days) / 7, 0) * 5
+ Mod(5 + Weekday(ReturnValue.SelectedDate) - Weekday(TravelValue.SelectedDate), 5)

 

Additionally, if you don't want the user to select Saturday or Sunday you can use this additional code

 

If(Or(Weekday(TravelValue.SelectedDate,StartOfWeek.Monday) in [6,7],
Weekday(ReturnValue.SelectedDate,StartOfWeek.Monday) in [6,7]),"Error",

RoundDown(DateDiff(TravelValue.SelectedDate, ReturnValue.SelectedDate, Days) / 7, 0) * 5
+ Mod(5 + Weekday(ReturnValue.SelectedDate) - Weekday(TravelValue.SelectedDate), 5))

 

Full details on how to handle Saturday and Sunday can be found in my previous post

https://powerusers.microsoft.com/t5/Building-PowerApps-Formerly/Exculde-Saturday-and-Sunday-individu...

 

---
Please click "Accept as Solution" if my response helped to solve your issue so that others may find it more quickly. If your thought the post was helpful please give it a "Thumbs Up."

View solution in original post

5 REPLIES 5
Super User
Super User

Re: exclude weekeneds in date calculations

Can you please explain further?  I would like to know what dates you are using as inputs and what answser the formula gave.  This will give us the ability to test a solution.

 

I assume you are using the formula supplied by this blog.  One known flaw is the user cannot select a weekend day (Saturday, Sunday) or else the formula does not work https://powerapps.microsoft.com/en-us/blog/excluding-weekends-and-holidays-in-date-differences-in-po...

abieba
Level: Powered On

Re: exclude weekeneds in date calculations

Hello @mdevaney 

i did not select weekend dates i used weekdays and was still not working as desired.

RoundDown(DateDiff(TravelValue.SelectedDate, ReturnValue.SelectedDate , Days) / 7, 0) * 5 +
Mod(5 + Weekday(TravelValue.SelectedDate) - Weekday(ReturnValue.SelectedDate), 5)

So its Duration = ReturnDate - TravelDate,  but the answers are not consitent. 

pic 1.JPGpic 2.JPGpic 3.JPGpic 4.JPG

Super User
Super User

Re: exclude weekeneds in date calculations

@abieba 

Something strange is happening with your formula when I tested in my own app.  Please try my code instead.  It seems to correct the problem we are having.

 

RoundDown(DateDiff(TravelValue.SelectedDate, ReturnValue.SelectedDate, Days) / 7, 0) * 5
+ Mod(5 + Weekday(ReturnValue.SelectedDate) - Weekday(TravelValue.SelectedDate), 5)

 

Additionally, if you don't want the user to select Saturday or Sunday you can use this additional code

 

If(Or(Weekday(TravelValue.SelectedDate,StartOfWeek.Monday) in [6,7],
Weekday(ReturnValue.SelectedDate,StartOfWeek.Monday) in [6,7]),"Error",

RoundDown(DateDiff(TravelValue.SelectedDate, ReturnValue.SelectedDate, Days) / 7, 0) * 5
+ Mod(5 + Weekday(ReturnValue.SelectedDate) - Weekday(TravelValue.SelectedDate), 5))

 

Full details on how to handle Saturday and Sunday can be found in my previous post

https://powerusers.microsoft.com/t5/Building-PowerApps-Formerly/Exculde-Saturday-and-Sunday-individu...

 

---
Please click "Accept as Solution" if my response helped to solve your issue so that others may find it more quickly. If your thought the post was helpful please give it a "Thumbs Up."

View solution in original post

abieba
Level: Powered On

Re: exclude weekeneds in date calculations

Hi @mdevaney ,

Thanks a lot it worked, i have gone through my code and your i am yet to see the reason why mine was not consistent?
is there any thing that should load onstart or, any detail the system needs to do that calculation?

The "error" when sat or sun is picked also worked too and i would use that as well.


Super User
Super User

Re: exclude weekeneds in date calculations

@abieba 

Nothing additional is needed here. Should work fine as is fortunately!

Helpful resources

Announcements
Better Together’ Contest Finalists Announced!

'Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Join THE global Microsoft Power Platform event series

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

thirdimage

Microsoft Business Applications Virtual Launch

Join us for the Microsoft Business Applications Virtual Launch Event on Thursday, April 2, 2020, at 8:00 AM PST.

thirdimage

Community Summit North America

Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (8,180)