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)

[TABLE="width: 1372"]
<tbody>[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]From[/TD]
[TD]20:00[/TD]
[TD]In the evening[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]To[/TD]
[TD]08:00[/TD]
[TD]in the morning[/TD]
[TD][/TD]
[TD="colspan: 2"]Ignoring the break!!![/TD]
[/TR]
[TR]
[TD]Employee[/TD]
[TD]IN[/TD]
[TD]OUT[/TD]
[TD]Break (mins)[/TD]
[TD]Total Hours[/TD]
[TD]Unsociable Hours[/TD]
[TD][/TD]
[TD][/TD]
[TD]Uns Should be[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]A[/TD]
[TD]04:30[/TD]
[TD]11:00[/TD]
[TD]60[/TD]
[TD]5.50[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]3.5[/TD]
[TD]Between 04:30 and 08:00 and the rest is normal hours[/TD]
[/TR]
[TR]
[TD]B[/TD]
[TD]20:00[/TD]
[TD]07:00[/TD]
[TD]0[/TD]
[TD]11.00[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]11[/TD]
[TD]Between 20:00 and 07:00 so no normal time[/TD]
[/TR]
[TR]
[TD]N[/TD]
[TD]19:00[/TD]
[TD]07:30[/TD]
[TD]30[/TD]
[TD]12.00[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]11.5[/TD]
[TD]Between 20:00 and 07:30 and the rest is normal hours[/TD]
[/TR]
[TR]
[TD]G[/TD]
[TD]22:00[/TD]
[TD]10:00[/TD]
[TD]45[/TD]
[TD]11.25[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]10[/TD]
[TD]Between 22:00 and 08:00 and the rest is normal hours[/TD]
[/TR]
[TR]
[TD]F[/TD]
[TD]23:30[/TD]
[TD]12:00[/TD]
[TD]50[/TD]
[TD]11.67[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]8.5[/TD]
[TD]Between 23:30 and 08:00 and the rest is normal hours[/TD]
[/TR]
[TR]
[TD]D[/TD]
[TD]00:00[/TD]
[TD]13:00[/TD]
[TD]40[/TD]
[TD]12.33[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]"[/TD]
[TD]"[/TD]
[/TR]
[TR]
[TD]E[/TD]
[TD]03:00[/TD]
[TD]16:00[/TD]
[TD]45[/TD]
[TD]12.25[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]"[/TD]
[TD]"[/TD]
[/TR]
[TR]
[TD]R[/TD]
[TD]05:00[/TD]
[TD]08:00[/TD]
[TD]50[/TD]
[TD]2.17[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]"[/TD]
[TD]"[/TD]
[/TR]
[TR]
[TD]T[/TD]
[TD]07:00[/TD]
[TD]16:00[/TD]
[TD]30[/TD]
[TD]8.50[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]"[/TD]
[TD]"[/TD]
[/TR]
[TR]
[TD]Y[/TD]
[TD]08:00[/TD]
[TD]19:00[/TD]
[TD]45[/TD]
[TD]10.25[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]"[/TD]
[TD]"[/TD]
[/TR]
[TR]
[TD]U[/TD]
[TD]09:00[/TD]
[TD]15:00[/TD]
[TD]60[/TD]
[TD]5.00[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]"[/TD]
[TD]"[/TD]
[/TR]
[TR]
[TD]I[/TD]
[TD]08:05[/TD]
[TD]16:00[/TD]
[TD]60[/TD]
[TD]6.92[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR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D]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]L[/TD]
[TD]23:45[/TD]
[TD]22:00[/TD]
[TD]150[/TD]
[TD]19.75[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]K[/TD]
[TD]01:00[/TD]
[TD]07:00[/TD]
[TD]45[/TD]
[TD]5.25[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Q[/TD]
[TD]01:25[/TD]
[TD]08:00[/TD]
[TD]40[/TD]
[TD]5.92[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]W[/TD]
[TD]02:00[/TD]
[TD]08:05[/TD]
[TD]90[/TD]
[TD]4.58[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]E[/TD]
[TD]03:00[/TD]
[TD]07:55[/TD]
[TD]85[/TD]
[TD]3.50[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

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

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
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
FromIn the evening
Toin the morningIgnoring the break!!!
EmployeeINOUTBreak (mins)Total HoursUnsociable HoursUns Should be
A
B
N
G
F
D
E

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"]20:00[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]2[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"]08:00[/TD]

[TD="align: right"][/TD]

[TD="align: center"]3[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]4[/TD]

[TD="align: right"]04:30[/TD]
[TD="align: right"]11:00[/TD]
[TD="align: right"]60[/TD]
[TD="align: right"] 5,50 [/TD]
[TD="align: right"] 3,50 [/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]3,5[/TD]

[TD="align: center"]5[/TD]

[TD="align: right"]20:00[/TD]
[TD="align: right"]07:00[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"] 11,00 [/TD]
[TD="align: right"] 11,00 [/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]11[/TD]

[TD="align: center"]6[/TD]

[TD="align: right"]19:00[/TD]
[TD="align: right"]07:30[/TD]
[TD="align: right"]30[/TD]
[TD="align: right"] 12,00 [/TD]
[TD="align: right"] 11,50 [/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]11,5[/TD]

[TD="align: center"]7[/TD]

[TD="align: right"]22:00[/TD]
[TD="align: right"]10:00[/TD]
[TD="align: right"]45[/TD]
[TD="align: right"] 11,25 [/TD]
[TD="align: right"] 10,00 [/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]10[/TD]

[TD="align: center"]8[/TD]

[TD="align: right"]23:30[/TD]
[TD="align: right"]12:00[/TD]
[TD="align: right"]50[/TD]
[TD="align: right"] 11,67 [/TD]
[TD="align: right"] 8,50 [/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]8,5[/TD]

[TD="align: center"]9[/TD]

[TD="align: right"]00:00[/TD]
[TD="align: right"]13:00[/TD]
[TD="align: right"]40[/TD]
[TD="align: right"] 12,33 [/TD]
[TD="align: right"] 8,00 [/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]10[/TD]

[TD="align: right"]03:00[/TD]
[TD="align: right"]16:00[/TD]
[TD="align: right"]45[/TD]
[TD="align: right"] 12,25 [/TD]
[TD="align: right"] 5,00 [/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

</tbody>
Sheet1

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Worksheet Formulas[TABLE="width: 100%"]
<thead>[TR="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]
[TH="width: 10px"]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
</thead><tbody>[TR]
[TH="width: 10px, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]E4[/TH]
[TD="align: left"]=((C4-B4+(B4>C4)-(D4/60/24)))*24[/TD]
[/TR]
[TR]
[TH="width: 10px, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]F4[/TH]
[TD="align: left"]=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[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]
 
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,223,228
Messages
6,170,874
Members
452,363
Latest member
merico17

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