Calculating time interval

RobD

New Member
Joined
Oct 7, 2002
Messages
10
I know this has been addressed before and have searched the archive but so far I've been unable to find something that works.

I need a formula to calculate the total number of hours and minutes between two date/time values. In addition the calculation must ignore the hours between 4:00AM and 10:00AM, include all weekends and holidays and have the ability to span multiple days.
I have tried simple subtraction but Excel doesn't seem to allow for more than a 24 hour difference. I also tried a solution I saw on http://www.mvps.org/dmcritchie/excel/datetime.htm but can't seem to get it to work either.
Any help appreciated.
Thanks -Rob-
 
Arggg! Still have a quirk with this. For some reason the following values produce 0:52:35 instead of the expected 0:01:00.
Any ideas?

11:00 AM 2:00 AM


23-Apr-02 1:07:25 AM
23-Apr-02 1:08:25 AM

0:52:35

=IF(INT(A3)=INT(A4),MAX(0,MOD(A4,1)-MAX(MOD(A3,1),$A$1))+MAX($B$1-MOD(A3,1),0),MAX(INT(A4)-INT(A3)-1,0)*(1-($A$1-$B$1))+MIN(1-MOD(A3,1),1-$A$1)+MAX(0,$B$1-MOD(A3,1))+MIN(MOD(A4,1),$B$1)+MAX(MOD(A4,1)-$A$1,0))
 
Upvote 0

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Oops. How about
=IF(INT(A3)=INT(A4),IF(OR(MOD(A4,1)<B1,MOD(A3,1)>A1),A4-A3,MAX(0,MOD(A4,1)-MAX(MOD(A3,1),$A$1))+MAX($B$1-MOD(A3,1),0)),MAX(INT(A4)-INT(A3)-1,0)*(1-($A$1-$B$1))+MIN(1-MOD(A3,1),1-$A$1)+MAX(0,$B$1-MOD(A3,1))+MIN(MOD(A4,1),$B$1)+MAX(MOD(A4,1)-$A$1,0))

I didn't account for both times being before or after the times when on the same day.

edited to disable HTML
This message was edited by IML on 2002-10-09 14:24
 
Upvote 0
With Day and Time in separate cells

=MAX(0,(B3-B2-1))*0.75+(C2>F2)*F2-C2+MIN(C3,F3)+MAX(C3-F4,0)

With Day and Time in the Same cell

=MAX(0,(DATEDIF(A1,A2,"d")-1))*0.75+(HOUR(A1)>10)*F2-TIME(HOUR(A1),MINUTE(A1),0)+MIN(TIME(HOUR(A2),MINUTE(A2),0),F3)+MAX(0,TIME(HOUR(A2),MINUTE(A2),0)-F4)
 
Upvote 0

Forum statistics

Threads
1,216,050
Messages
6,128,498
Members
449,455
Latest member
jesski

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