Calculate worked hours based upon criteria

Skybluekid

Well-known Member
Joined
Apr 17, 2012
Messages
1,229
Office Version
  1. 365
Platform
  1. Windows
Hi All,


I have a sheet where it records a time when one of our trucks goes into a dealer. It also records the time the trucks leaves the dealer. I would like to workout how long the vehicle has been stood in the dealer. That is easy to do, but in order to be accurate, I would like the dealers opening hours to be considered.

For example, The truck enters a dealer, and we have a time stamp of 5/8/2019 08:00. The truck leaves on the 12/8/19 12:00. The Dealer opening hours are 08:00 - 23:00 Mon-Fri 08:00 - 12:00 Saturday Closed on Sunday.

So in the above scenario, the answer would be 75hrs


Thanks in Advance
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Hi,

I can't match your answer but i assume you've made a calculation error.
Check my table and formula and try if it suits your need:


Book1
ABCDE
1InOutTotal
25-8-2019 08:0012-8-2019 12:0083:00:00
3
405-08-2019Monday08:0023:0015:00
506-08-2019Tuesday08:0023:0015:00
607-08-2019Wednesday08:0023:0015:00
708-08-2019Thursday08:0023:0015:00
809-08-2019Friday08:0023:0015:00
910-08-2019Saturday08:0012:0004:00
1011-08-2019Sunday
1112-08-2019Monday08:0012:0004:00
1283:00:00
Sheet3
Cell Formulas
RangeFormula
C2=(NETWORKDAYS.INTL(A2,B2,1)-1)*("23:00"-"08:00")+IF(NETWORKDAYS.INTL(B2,B2,1),MEDIAN(MOD(B2,1),"23:00","08:00"),"23:00")-MEDIAN(NETWORKDAYS.INTL(A2,A2,1)*MOD(A2,1),"23:00","08:00")+(NETWORKDAYS.INTL(A2,B2,"1111101")-1)*("12:00"-"08:00")+IF(NETWORKDAYS.INTL(B2,B2,"1111101"),MEDIAN(MOD(B2,1),"12:00","08:00"),"12:00")-MEDIAN(NETWORKDAYS.INTL(A2,A2,"1111101")*MOD(A2,1),"12:00","08:00")
 
Upvote 0
Hello Jorismoerings, I was wondering why i am getting a different figure with your formula.


Excel 2013/2016
ABCDE
1InOutTotal
25/8/2019 8:0012/8/2019 12:00100.79
3
48-May-19Monday8:0023:0015:00
58-Jun-19Tuesday8:0023:0015:00
68-Jul-19Wednesday8:0023:0015:00
78-Aug-19Thursday8:0023:0015:00
88-Sep-19Friday8:0023:0015:00
98-Oct-19Saturday8:0012:004:00
108-Nov-19Sunday
118-Dec-19Monday8:0012:004:00
1283:00:00
Sheet1
Cell Formulas
RangeFormula
C2=(NETWORKDAYS.INTL(A2,B2,1)-1)*("23:00"-"08:00")+IF(NETWORKDAYS.INTL(B2,B2,1),MEDIAN(MOD(B2,1),"23:00","08:00"),"23:00")-MEDIAN(NETWORKDAYS.INTL(A2,A2,1)*MOD(A2,1),"23:00","08:00")+(NETWORKDAYS.INTL(A2,B2,"1111101")-1)*("12:00"-"08:00")+IF(NETWORKDAYS.INTL(B2,B2,"1111101"),MEDIAN(MOD(B2,1),"12:00","08:00"),"12:00")-MEDIAN(NETWORKDAYS.INTL(A2,A2,"1111101")*MOD(A2,1),"12:00","08:00")
 
Upvote 0
@Sam_D_Ben,

Hi, i'm getting the same result as you howeverthe devil is in the details.
The OP ask a question regarding a timeframe and from his/her originating country i deducted the date/time notation was UK.
5/8/2019 08:00. The truck leaves on the 12/8/19 12:00

doesn't mean may 8th tll december 8th but August 5th till August 12th.

When entered, these are the results:

Book1
ABC
1InOutTotal
28 May 2019 08:008 December 2019 12:00100,7916667
35 August 2019 08:0012 August 2019 12:003,458333333
Sheet1
Cell Formulas
RangeFormula
C2=(NETWORKDAYS.INTL(A2,B2,1)-1)*("23:00"-"08:00")+IF(NETWORKDAYS.INTL(B2,B2,1),MEDIAN(MOD(B2,1),"23:00","08:00"),"23:00")-MEDIAN(NETWORKDAYS.INTL(A2,A2,1)*MOD(A2,1),"23:00","08:00")+(NETWORKDAYS.INTL(A2,B2,"1111101")-1)*("12:00"-"08:00")+IF(NETWORKDAYS.INTL(B2,B2,"1111101"),MEDIAN(MOD(B2,1),"12:00","08:00"),"12:00")-MEDIAN(NETWORKDAYS.INTL(A2,A2,"1111101")*MOD(A2,1),"12:00","08:00")
C3=(NETWORKDAYS.INTL(A3,B3,1)-1)*("23:00"-"08:00")+IF(NETWORKDAYS.INTL(B3,B3,1),MEDIAN(MOD(B3,1),"23:00","08:00"),"23:00")-MEDIAN(NETWORKDAYS.INTL(A3,A3,1)*MOD(A3,1),"23:00","08:00")+(NETWORKDAYS.INTL(A3,B3,"1111101")-1)*("12:00"-"08:00")+IF(NETWORKDAYS.INTL(B3,B3,"1111101"),MEDIAN(MOD(B3,1),"12:00","08:00"),"12:00")-MEDIAN(NETWORKDAYS.INTL(A3,A3,"1111101")*MOD(A3,1),"12:00","08:00")
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top