Total hours that fall between two times

egemencoskun

New Member
Joined
Feb 9, 2010
Messages
19
Hi All,

Need a formula to calculate total number of hours that fall between 2 specific times as below.

Formula should go to Unsociable Hours Column (F)

From20:00In the evening
To08:00in the morningIgnoring the break!!!
EmployeeINOUTBreak (mins)Total HoursUnsociable HoursUns Should be
A04:3011:00605.503.5Between 04:30 and 08:00 and the rest is normal hours
B20:0007:00011.0011Between 20:00 and 07:00 so no normal time
N19:0007:303012.0011.5Between 20:00 and 07:30 and the rest is normal hours
G22:0010:004511.2510Between 22:00 and 08:00 and the rest is normal hours
F23:3012:005011.678.5Between 23:30 and 08:00 and the rest is normal hours
D00:0013:004012.33""
E03:0016:004512.25""
R05:0008:00502.17""
T07:0016:00308.50""
Y08:0019:004510.25""
U09:0015:00605.00""
I08:0516:00606.92
O07:5507:004522.33
P09:0006:005020.17
Z11:0019:00557.08
X13:0022:00458.25
C15:0023:00507.17
V17:0001:00607.00
B19:0003:00607.00
N21:0004:00755.75
M23:0009:00958.42
L23:4522:0015019.75
K01:0007:00455.25
Q01:2508:00405.92
W02:0008:05904.58
E03:0007:55853.50

<tbody>
</tbody>

I have a sample SS but cant figure how to upload.
 
Last edited:

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Does it make any difference if break time falls in normal hour or unsociable hour? I'd think it would but you don't specify what period the break time is in. Seems to me it doesn't matter.
 
Upvote 0
Hi,

assumed lunch is during sociable hours.
See if this works for you:


Excel 2016 (Windows) 64 bit
ABCDEFGHI
1From20:00In the evening
2To08:00in the morningIgnoring the break!!!
3EmployeeINOUTBreak (mins)Total HoursUnsociable HoursUns Should be
4A04:3011:00605,503,503,5
5B20:0007:00011,0011,0011
6N19:0007:303012,0011,5011,5
7G22:0010:004511,2510,0010
8F23:3012:005011,678,508,5
9D00:0013:004012,338,00
10E03:0016:004512,255,00
Sheet1
Cell Formulas
RangeFormula
E4=((C4-B4+(B4>C4)-(D4/60/24)))*24
F4=E4-(IF(B4C4,$F$1)-MAX(B4,$F$2),MAX(0,$F$1-B4)+MAX(0,C4-$F$2))-(D4/60/24))*24
 
Upvote 0
Thanks for posting it, the formula works on F4 until you get to an example like employee "U" .. is there anyway to get around this? Thanks!

Hi,

assumed lunch is during sociable hours.
See if this works for you:

Excel 2016 (Windows) 64 bit
ABCDEFGHI
1From20:00In the evening
2To08:00in the morningIgnoring the break!!!
3EmployeeINOUTBreak (mins)Total HoursUnsociable HoursUns Should be
4A04:3011:0060 5,50 3,50 3,5
5B20:0007:000 11,00 11,00 11
6N19:0007:3030 12,00 11,50 11,5
7G22:0010:0045 11,25 10,00 10
8F23:3012:0050 11,67 8,50 8,5
9D00:0013:0040 12,33 8,00
10E03:0016:0045 12,25 5,00

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

Worksheet Formulas
CellFormula
E4=((C4-B4+(B4>C4)-(D4/60/24)))*24
F4=E4-(IF(B4<C4,MIN(C4,$F$1)-MAX(B4,$F$2),MAX(0,$F$1-B4)+MAX(0,C4-$F$2))-(D4/60/24))*24

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

<tbody>
</tbody>
 
Upvote 0
Hi,

This is the result from the formula for employee U. I don't understand to what i need to get around. From my perspective the result of unsociable hours is correct. Can you explain what you mean.


Book1
ABCDEF
3EmployeeINOUTBreak (mins)Total HoursUnsociable Hours
4A04:3011:00605,53,5
5B20:0007:0001111,0
6N19:0007:30301211,5
7G22:0010:004511,2510,0
8F23:3012:005011,678,5
9D00:0013:004012,338,0
10E03:0016:004512,255,0
11R05:0008:00502,173,0
12T07:0016:00308,51,0
13Y08:0019:004510,250,0
14U09:0015:006050,0
15I08:0516:00606,920,0
Sheet1
Cell Formulas
RangeFormula
F14=E14-(IF(B14C14,$F$1)-MAX(B14,$F$2),MAX(0,$F$1-B14)+MAX(0,C14-$F$2))-(D14/60/24))*24
 
Upvote 0
Hi Joris,
Thanks for replying back! I agree that it should return 0.0 hours for employee U.
But for some reason, when I use the formula - it gives me a negative value.

for example:
1:15 PM to 3:34 PM returns -.07
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,107
Messages
6,128,866
Members
449,475
Latest member
Parik11

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