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

Share - calculate working days between two given dates

Hello, I was trying to find the method to return the number of working days between two given dates and found the following article

 

https://powerapps.microsoft.com/en-us/blog/excluding-weekends-and-holidays-in-date-differences-in-po...

 

However, as the author mentioned "Notice that the partial week calculation given above will not work if the start or end dates fall on weekends"

 

So I spent some time writing the following formula which seems work for weekends too:

 

If(IsNewRequestFormValid, RoundDown(DateDiff(DatePickerFrom.SelectedDate, DatePickerTo.SelectedDate, Days) / 7, 0) * 5 +
If(Weekday(DatePickerTo.SelectedDate) >= Weekday(DatePickerFrom.SelectedDate),
If(Weekday(DatePickerTo.SelectedDate) = Weekday(DatePickerFrom.SelectedDate) && (Weekday(DatePickerTo.SelectedDate) = 1 || Weekday(DatePickerTo.SelectedDate) = 7),
0,
If(RoundDown((Weekday(DatePickerTo.SelectedDate) - Weekday(DatePickerFrom.SelectedDate))/5,0) >= 1,
5,
If(Weekday(DatePickerTo.SelectedDate) = 7,
Weekday(DatePickerTo.SelectedDate) - Weekday(DatePickerFrom.SelectedDate),
If(Weekday(DatePickerFrom.SelectedDate) = 1,
Weekday(DatePickerTo.SelectedDate) - Weekday(DatePickerFrom.SelectedDate),
Mod(Weekday(DatePickerTo.SelectedDate) - Weekday(DatePickerFrom.SelectedDate), 5) + 1)))),
(7 - Weekday(DatePickerFrom.SelectedDate) + Weekday(DatePickerTo.SelectedDate) - 1)))

 

I am sure it can be improved, so please feel free to make any enhancement. 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: Share - calculate working days between two given dates

Hi @Li,

 

Thanks for your sharing.

 

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
Community Support Team
Community Support Team

Re: Share - calculate working days between two given dates

Hi @Li,

 

Thanks for your sharing.

 

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Medalow
Level: Powered On

Re: Share - calculate working days between two given dates

@Li, thank you so much for sharing this! You are a life-saver 🙂 

Cheers!

lpr
Level: Powered On

Re: Share - calculate working days between two given dates

thanks for sharing but;

  1. What is IsNewRequestFormValid? is it a custom variable just for your case?
mogulman
Level 8

Re: Share - calculate working days between two given dates

I don't know what you mean by working day but my requirement excluded bank holidays so Christmas Day, New Years day don't count as working days.  Here is list:

 

DescriptionHolidayDate
New Year's Day1/1/2019
Birthday of Martin Luther King, Jr.1/21/2019
Washington's Birthday2/18/2019
Memorial Day5/27/2019
Independence Day7/4/2019
Labor Day9/2/2019
Columbus Day10/14/2019
Veterans Day11/11/2019
Thanksgiving Day11/28/2019
Christmas Day12/25/2019
New Year's Day1/1/2020

 

I also need to add/subtract working days from a date.  For example something is due in 10 business days (BD) or send a reminder notice 3 BD prior to due date.  The date could be a non workday.  I found using PA to do this was impossible.  I ended up doing an Azure Function.  

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

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

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors
Users Online
Currently online: 149 members 5,310 guests
Please welcome our newest community members: