Calculating elapsed hours with weekends.

MasterK

New Member
Joined
Jan 15, 2015
Messages
15
I'm trying to calculate elapsed time in hours from a start date/time to an end date/time.

Work hours are M-F, 6AM - 6PM.

Below is the formula I'm using.

=(NETWORKDAYS(B3,C3)-1)*("18:00"-"6:00")+MOD(C3,1)-MOD(B3,1)

The problem I'm having is if the start day is after business hours or on Saturday or Sunday, The hours don't calculate correctly.

I need your help with a formula correction that will resolve the scenarios below in RED

Start DateEnd DateElapsed TimeCommentCorrect Value
8/17/19 15:30 (Sun)

<tbody>
</tbody>
8/19/19 17:30 (Mon)

<tbody>
</tbody>
2:00Incorrect value11:30 hrs
8/14/19 18:30 (Wed)

<tbody>
</tbody>
8/15/19 17:30 (Thu)

<tbody>
</tbody>
11:00Incorrect Value11:30 hrs
8/14/19 7:00 (Wed)

<tbody>
</tbody>
8/16/19 13:00 (Fri)

<tbody>
</tbody>
30:00Correct30:00 hrs

<tbody>
</tbody>


Thanks much for your assistance in advance.
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Hello,

Not sure to understand your question ... since Networkdays is designed to exclude week-ends ...:wink:
 
Upvote 0
Hello,

Not sure to understand your question ... since Networkdays is designed to exclude week-ends ...:wink:

The problem comes when the start date is on a weekend our outside of the designated work hours.
What I'm tracking is specific reports being reconciled within a shipment departure time.
The departures often occur on weekends or the early hours of the morning. My staff it not responsible
for the elapsed hour during non-business days/times. But, I can't stop the shipments from leaving
during those times.
 
Upvote 0
Try

Book1
BCD
38/17/2019 15:308/19/2019 17:3011:30:00
48/14/2019 18:308/15/2019 17:3011:30:00
58/14/2019 7:008/16/2019 13:0030:00:00
Sheet1
Cell Formulas
RangeFormula
D3=(NETWORKDAYS(IF(WEEKDAY(B3,2)=6,INT(B3)+2+0.25,IF(OR(WEEKDAY(B3,2)=7,MOD(B3,1)>0.75),INT(B3)+1+0.25,B3)),C3)-1)*("18:00"-"6:00")+MOD(C3,1)-MOD(IF(WEEKDAY(B3,2)=6,INT(B3)+2+0.25,IF(OR(WEEKDAY(B3,2)=7,MOD(B3,1)>0.75),INT(B3)+1+0.25,B3)),1)
 
Upvote 0
Try
BCD
38/17/2019 15:308/19/2019 17:3011:30:00
48/14/2019 18:308/15/2019 17:3011:30:00
58/14/2019 7:008/16/2019 13:0030:00:00

<colgroup><col style="width: 25pxpx"><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1

Worksheet Formulas
CellFormula
D3=(NETWORKDAYS(IF(WEEKDAY(B3,2)=6,INT(B3)+2+0.25,IF(OR(WEEKDAY(B3,2)=7,MOD(B3,1)>0.75),INT(B3)+1+0.25,B3)),C3)-1)*("18:00"-"6:00")+MOD(C3,1)-MOD(IF(WEEKDAY(B3,2)=6,INT(B3)+2+0.25,IF(OR(WEEKDAY(B3,2)=7,MOD(B3,1)>0.75),INT(B3)+1+0.25,B3)),1)

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>

Amazing, thank you !
 
Upvote 0
Forgot to account for if it is a work day but before 6AM this should cover that.


Book1
ABC
28/17/2019 15:308/19/2019 17:3011:30:00
38/14/2019 18:308/15/2019 17:3011:30:00
48/14/2019 7:008/16/2019 13:0030:00:00
58/22/2019 5:008/22/2019 7:001:00:00
Sheet1
Cell Formulas
RangeFormula
C2=(NETWORKDAYS(IF(WEEKDAY(A2,2)=6,INT(A2)+2+0.25,IF(OR(WEEKDAY(A2,2)=7,MOD(A2,1)>0.75),INT(A2)+1+0.25,IF(AND(OR(WEEKDAY(A2,2)<>6,WEEKDAY(A2,2)<>7),MOD(A2,1)<0.25),INT(A2)+0.25,A2))),B2)-1)*("18:00"-"6:00")+MOD(B2,1)-MOD(IF(WEEKDAY(A2,2)=6,INT(A2)+2+0.25,IF(OR(WEEKDAY(A2,2)=7,MOD(A2,1)>0.75),INT(A2)+1+0.25,IF(AND(OR(WEEKDAY(A2,2)<>6,WEEKDAY(A2,2)<>7),MOD(A2,1)<0.25),INT(A2)+0.25,A2))),1)
 
Upvote 0
Forgot to account for if it is a work day but before 6AM this should cover that.

ABC
28/17/2019 15:308/19/2019 17:3011:30:00
38/14/2019 18:308/15/2019 17:3011:30:00
48/14/2019 7:008/16/2019 13:0030:00:00
58/22/2019 5:008/22/2019 7:001:00:00

<colgroup><col style="width: 25pxpx"><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1

Worksheet Formulas
CellFormula
C2=(NETWORKDAYS(IF(WEEKDAY(A2,2)=6,INT(A2)+2+0.25,IF(OR(WEEKDAY(A2,2)=7,MOD(A2,1)>0.75),INT(A2)+1+0.25,IF(AND(OR(WEEKDAY(A2,2)<>6,WEEKDAY(A2,2)<>7),MOD(A2,1)<0.25),INT(A2)+0.25,A2))),B2)-1)*("18:00"-"6:00")+MOD(B2,1)-MOD(IF(WEEKDAY(A2,2)=6,INT(A2)+2+0.25,IF(OR(WEEKDAY(A2,2)=7,MOD(A2,1)>0.75),INT(A2)+1+0.25,IF(AND(OR(WEEKDAY(A2,2)<>6,WEEKDAY(A2,2)<>7),MOD(A2,1)<0.25),INT(A2)+0.25,A2))),1)

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>

Thanks again. I didn't notice that before but not it's spot on.
 
Upvote 0
I'm back again. I usually know where to add holidays in simpler networkdays strings, but I've tried to dabble here and it's not working. I can either list them out individually or make a sheet with a table. Either way I just need to know where to insert.

Thanks in advance!
 
Upvote 0
RED= start date
Blue= end date
F2:F7 = holiday list

Code:
=(NETWORKDAYS([COLOR=#ff0000]IF(WEEKDAY(A2,2)=6,INT(A2)+2+0.25,IF(OR(WEEKDAY(A2,2)=7,MOD(A2,1)>0.75),INT(A2)+1+0.25,IF(AND(OR(WEEKDAY(A2,2)<>6,WEEKDAY(A2,2)<>7),MOD(A2,1)<0.25),INT(A2)+0.25,A2)))[/COLOR],[COLOR=#0000cd]B2,[/COLOR][COLOR=#ffa500]F2:F7[/COLOR])-1)*("18:00"-"6:00")+MOD(B2,1)-MOD(IF(WEEKDAY(A2,2)=6,INT(A2)+2+0.25,IF(OR(WEEKDAY(A2,2)=7,MOD(A2,1)>0.75),INT(A2)+1+0.25,IF(AND(OR(WEEKDAY(A2,2)<>6,WEEKDAY(A2,2)<>7),MOD(A2,1)<0.25),INT(A2)+0.25,A2))),1)
 
Upvote 0
RED= start date
Blue= end date
F2:F7 = holiday list

Code:
=(NETWORKDAYS([COLOR=#ff0000]IF(WEEKDAY(A2,2)=6,INT(A2)+2+0.25,IF(OR(WEEKDAY(A2,2)=7,MOD(A2,1)>0.75),INT(A2)+1+0.25,IF(AND(OR(WEEKDAY(A2,2)<>6,WEEKDAY(A2,2)<>7),MOD(A2,1)<0.25),INT(A2)+0.25,A2)))[/COLOR],[COLOR=#0000cd]B2,[/COLOR][COLOR=#ffa500]F2:F7[/COLOR])-1)*("18:00"-"6:00")+MOD(B2,1)-MOD(IF(WEEKDAY(A2,2)=6,INT(A2)+2+0.25,IF(OR(WEEKDAY(A2,2)=7,MOD(A2,1)>0.75),INT(A2)+1+0.25,IF(AND(OR(WEEKDAY(A2,2)<>6,WEEKDAY(A2,2)<>7),MOD(A2,1)<0.25),INT(A2)+0.25,A2))),1)

Lifesaver. I had a manual formula subtracting hours. This will be much easier.
 
Upvote 0

Forum statistics

Threads
1,214,573
Messages
6,120,310
Members
448,955
Latest member
Dreamz high

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