Difference between two dates/times, excluding weekends...

dean_woods

New Member
Joined
Apr 22, 2005
Messages
5
I would like to work out the difference (in hh:mm:ss) between two periods of time (Start time and End time) (dd/mm/yyyy hh:mm:ss), the formula needs to exclude weekends. Also...

Here's the bit where I'm not too sure how to factor into the formula (thats if it is at all possible!)::banghead:

My team provide support between 08:00 & 18:00. If a jobs Start time is after 18:00 the Service Level Agreement for my team does not start until 08:00 the following morning. Does that make sense :-?

Any help/ideas would be appreciated. Thanks
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Do you only want to calculate the WORK hours between the two time/date values?

e.g. 14:30 on Friday to 15:30 tomorrow will be 21 hours

If so

=(NETWORKDAYS(A1,B1)-1)*5/12+MOD(B1,1)-MOD(A1,1)

format as [h]:mm:ss

where A1 is start time/date and B1 the end time/date
 
Upvote 0
Thanks for the replies.
Yep, would like to calculate the difference between Start and End times (but only between 08:00 - 18:00)
 
Upvote 0
I looked at this again and realised that the formula I suggested wouldn't give the correct results if the start or end dates/times were at the weekend or on holidays.

Here's a better version, which seems to work OK for all the circumstances I tried.

It only calculates the work hours between the dates/times given, also excludes holidays - you list those and the formula references the range

It sounds a pretty simple proposition but it's a tricky little critter. My formula's now pretty long but still not nearly as long as Pearson's posted above. 8-)

Please let me know if this is any good for you - I'm sure I can adjust if necessary, if you don't need the holidays included, that will shorten the formula somewhat
overtime.xls
ABCDEFG
1
2
3StartEndElapsed work hourshoursholidays
429/04/2005 18:3003/05/2005 07:300:00:0008:0027/12/2004
522/04/2005 17:3026/04/2005 03:3010:30:0018:0028/12/2004
626/04/2005 22:0028/04/2005 04:0010:00:0002/01/2005
727/04/2005 22:0004/05/2005 22:0040:00:0025/03/2005
801/04/2005 17:2028/04/2005 08:10180:50:0028/03/2005
901/04/2004 17:2028/04/2005 22:102760:40:0002/05/2005
1030/05/2005
1129/08/2005
12
Time difference


Formula in C4 copied down column

=IF(OR(A4="",B4=""),"",(NETWORKDAYS(A4,B4,$F$4:$F$12)-1)*($E$5-$E$4)+IF(OR(ISNUMBER(MATCH(INT(B4),$F$4:$F$12,0)),WEEKDAY(B4,2)>5),$E$5,MEDIAN(MOD(B4,1),$E$5,$E$4))-IF(OR(ISNUMBER(MATCH(INT(A4),$F$4:$F$12,0)),WEEKDAY(A4,2)>5),$E$4,MEDIAN(MOD(A4,1),$E$5,$E$4)))
 
Upvote 0
Yes,

Given the formula I suggested these can be listed in F4:F12 - obviously you can change the range or extend it
 
Upvote 0

Forum statistics

Threads
1,226,349
Messages
6,190,444
Members
453,609
Latest member
iamcpdev

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