Hi Tom,
Perhaps you want to look at Chip Pearson's page on this topic:
http://www.cpearson.com/excel/DateTimeWS.htm
This reference is very frequently given and contains a formula calculating the
hours. However, it shows the same problems when StartDT and/or EndDT are
'offlimit' (aka not within DayStart and DayEnd)
BTW, no disrespect for a very good site nonetheless.
We're talking about the second formula (the one, calculating the hours):
"=IF(AND(INT(StartDT)=INT ... DayEnd-DayStart)),2))))))
Example: For DayStart=8:00 and DayEnd=17:00 ' the user's param
StartDt: Thu 2002-08-15 10:00
EndDt: Thu 2002-08-15 18:00
Result = 8
Expected result : 7:00 (or 7 if you want)
The only formula that works in all cases:
=IF(StartDT>EndDT,0,NETWORKDAYS(StartDT,EndDT,Holidays)*(DayEnd-DayStart)
-IF(NETWORKDAYS(StartDT,StartDT,Holidays),
MAX(0,MIN(DayEnd,MOD(StartDT,1))-DayStart),0)
-IF(NETWORKDAYS(EndDT,EndDT,Holidays),
MAX(0,DayEnd-MAX(MOD(EndDT,1),DayStart)),0))
It's shorter and covers all cases AFAIK.
Regards,
Daniel M.