Calculate only working hours between two dates with several constraints (includes weekend, excludes holidays, working hours ranges different each day)

jilianbenss

New Member
Joined
Aug 20, 2018
Messages
3
Hi all,


I have read many threads regarding the calculation of working hours between two dates, including the following thread https://www.mrexcel.com/forum/excel...urs-between-two-dates-excluding-weekends.html and the great answers from member barry houdini and others (e.g. pedrowave). I am really grateful for the patience and quality of barry's and other members of this board.

I am facing a difficult calculation as there are many constraints.

I need to calculate the time elapsed between two tickets raised. A client raises a ticket, at any time and any day, and our staff resolves the ticket within our working hours.
I then need to calculate the time it takes to resolve the ticket within the working hours, including the weekend, and excluding bank holidays. If a ticket is resolved outside of working hours and days, only the time WITHIN the working hours and days should be counted.

I have found great answers that either include or exclude weekend. However, I have 3 major constraints that make all the formulas and solutions proposed in the mentioned thread unusable:




  • I manage several locations, each location has different working hours and different working days. E.g. NYC is open from Monday to Sunday, with different hours for each day. Los Angeles only Monday to Friday. New Orleans Monday to Saturday. Again, the working hours are different each day (e.g. Monday to Friday 5am 730pm, Saturday 6am - 2pm, Sunday 9am - 5pm).
  • Each location has different Bank Holidays because they're located in different states (and sometimes countries).
  • Some of our locations have working hours that finish late into the night (e.g. 5am to 1am).

I know NETWORKDAYS cannot be used since it's a Mon-Fri formula, and I've tried to adapt barry houdini's formula:
=(SUMPRODUCT(INT((WEEKDAY(A2-{2,3,4,5,6,7})+INT(B2)-INT(A2))/7),{9,9,9,9,9,4})-SUMPRODUCT((H$1:H$10>A2)*(H$1:H$10< B2),LOOKUP(WEEKDAY(H$1:H$10),{1,7},{9,4}))+(MOD(B2,1)-MOD(A2,1))*24+IF(WEEKDAY(A2)=7,8,7)-IF(WEEKDAY(B2)=7,12,16))/24

A2 B2 being start date and finish date, H1:H10 being holidays.

However, this formula has fixed working hours, where I need to change the working hours for each day and each location. Also, I cannot seem to calculate properly working hours when they extend to the day after (e.g. office open from 5am Tuesday to 1am Wednesday).



The file looks like this, I'm trying to calculate in the column Working Hours
Tab 1:


Ticket numberOrganizationDate ReportedDate of resolutionWorking Hours
12583Philadelphia11/02/2017 16:5913/02/2017 10:29
19029NYC8/11/2016 17:518/11/2016 20:31
12584LA11/02/2017 16:5913/02/2017 10:29
12488Kuala Lumpur9/02/2017 19:5910/02/2017 14:15
13284Mumbai24/02/2017 21:5025/02/2017 9:27
19460New Orleans18/11/2016 11:5419/11/2016 10:54
14784Charlotteville27/03/2017 0:0027/03/2017 13:18

<tbody>
</tbody>


Tab 2 Working hours:

Monday OpeningMonday ClosingTuesday OpeningTuesday ClosingWednesday OpeningWednesday ClosingThursday OpeningThursday ClosingFriday OpeningFriday ClosingSaturday OpeningSaturday ClosingSunday OpeningSunday Closing
Business
NYC5:00 AM1:00 AM5:00 AM1:00 AM5:00 AM1:00 AM5:00 AM1:00 AM5:00 AM1:00 AM5:00 AM12:00 AM2:00 PM12:00 AM
Philadelphia5:30 AM7:00 PM5:30 AM7:00 PM5:30 AM7:00 PM5:30 AM7:00 PM5:30 AM7:00 PM6:00 AM2:00 PM9:00 AM5:00 PM
Charlotteville5:00 AM8:00 PM5:00 AM8:00 PM5:00 AM8:00 PM5:00 AM8:00 PM5:00 AM8:00 PM5:00 AM1:00 PMN/AN/A
New Orleans5:00 AM6:00 PM5:00 AM6:00 PM5:00 AM6:00 PM5:00 AM6:00 PM5:00 AM6:00 PM4:00 AM1:00 PMN/AN/A
LA5:00 AM6:00 PM5:00 AM6:00 PM5:00 AM6:00 PM5:00 AM6:00 PM5:00 AM6:00 PMN/AN/AN/AN/A
Kuala Lumpur5:00 AM6:00 PM5:00 AM6:00 PM5:00 AM6:00 PM5:00 AM6:00 PM5:00 AM6:00 PMN/AN/AN/AN/A
Mumbai6:00 AM9:00 AM6:00 AM9:00 AM6:00 AM9:00 AM6:00 AM9:00 AM6:00 AM9:00 AMN/AN/AN/AN/A

<tbody>
</tbody>


Tab 3 Bank holidays to exclude:

PhiladelphiaNYCCharlottevilleNew OrleansKuala LumpurMumbaiLA
1/01/20171/01/20161/01/20171/01/20161/01/20171/01/20161/01/2017
2/02/201726/01/20162/02/201726/01/20162/02/201726/01/20162/02/2017
26/01/20177/03/201626/01/20177/03/201626/01/20177/03/201626/01/2017
14/04/201725/03/201614/04/201725/03/201614/04/201725/03/201614/04/2017
15/04/201728/03/201615/04/201728/03/201615/04/201728/03/201615/04/2017
16/04/201725/04/201616/04/201725/04/201616/04/201725/04/201616/04/2017
17/04/20176/06/201617/04/20176/06/201617/04/20176/06/201617/04/2017

<tbody>
</tbody>


If anyone could help me I've been literally spending days on this.


Thanks

Cheers
 

Some videos you may like

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Watch MrExcel Video

Forum statistics

Threads
1,109,013
Messages
5,526,266
Members
409,689
Latest member
martin_br

This Week's Hot Topics

Top