Help with 'hours worked' calculation...

Barquois

New Member
Joined
Jun 17, 2011
Messages
23
Hi,

I have a query about calculating the numbers of hours worked using a formula.

In essence I have a start and end date/time which I can happily subtract from each other to get a the number of hours. BUT, I want to be able to automatically calculate the amount of time spent between two times BUT only where it falls in a 8am - 4pm range.

For example, if a user starts a piece of work at 3pm on 1 day and then continues it the next day from 8am and finishes at 10am I want to be able to make sure it calculates this as 3 hours and not 19 hours which it would do with a straight subtraction.

Does this make sense?

Regards

Nick
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Maybe this:

Note: If the function NETWORKDAYS is not available, and returns the #NAME? error, install and load the Analysis ToolPak add-in.

<b>Excel 2007</b><table cellpadding="2.5px" rules="all" style=";background-color: #FFFFFF;border: 1px solid;border-collapse: collapse; border-color: #A6AAB6"><colgroup><col width="25px" style="background-color: #E0E0F0" /><col /><col /><col /><col /><col /><col /><col /></colgroup><thead><tr style=" background-color: #E0E0F0;text-align: center;color: #161120"><th></th><th>A</th><th>B</th><th>C</th><th>D</th><th>E</th><th>F</th><th>G</th></tr></thead><tbody><tr ><td style="color: #161120;text-align: center;">1</td><td style="text-align: center;;">Start</td><td style="text-align: center;;">End</td><td style="text-align: center;;">Time worked</td><td style="text-align: right;;"></td><td style="text-align: center;;">Range</td><td style="text-align: center;;">8:00</td><td style="text-align: center;;">16:00</td></tr><tr ><td style="color: #161120;text-align: center;">2</td><td style="text-align: center;;">8/1/2011 15:00</td><td style="text-align: center;;">8/2/2011 10:00</td><td style="text-align: center;;">3:00</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">3</td><td style="text-align: center;;">8/1/2011 15:00</td><td style="text-align: center;;">8/4/2011 11:30</td><td style="text-align: center;;">20:30</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">4</td><td style="text-align: center;;">8/1/2011 8:00</td><td style="text-align: center;;">8/1/2011 10:00</td><td style="text-align: center;;">2:00</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">5</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style=";">******</td><td style=";">******</td><td style=";">******</td><td style=";">******</td></tr></tbody></table><p style="width:3.6em;font-weight:bold;margin:0;padding:0.2em 0.6em 0.2em 0.5em;border: 1px solid #A6AAB6;border-top:none;text-align: center;background-color: #E0E0F0;color: #161120">Sheet4</p><br /><br /><table width="85%" cellpadding="2.5px" rules="all" style=";border: 2px solid black;border-collapse:collapse;padding: 0.4em;background-color: #FFFFFF" ><tr><td style="padding:6px" ><b>Worksheet Formulas</b><table cellpadding="2.5px" width="100%" rules="all" style="border: 1px solid;text-align:center;background-color: #FFFFFF;border-collapse: collapse; border-color: #A6AAB6"><thead><tr style=" background-color: #E0E0F0;color: #161120"><th width="10px">Cell</th><th style="text-align:left;padding-left:5px;">Formula</th></tr></thead><tbody><tr><th width="10px" style=" background-color: #E0E0F0;color: #161120">C2</th><td style="text-align:left">=IF(<font color="Blue">NETWORKDAYS(<font color="Red">A2,B2</font>)>1,$G$1-A2+B2-$F$1+IF(<font color="Red">NETWORKDAYS(<font color="Green">A2,B2</font>)>2,(<font color="Green">NETWORKDAYS(<font color="Purple">A2,B2</font>)-2</font>)*(<font color="Green">$G$1-$F$1</font>),0</font>),B2-A2</font>)</td></tr></tbody></table></td></tr></table><br />
Markmzz
 
Upvote 0
Thanks Mark,

This works an absolute treat when the hours are fixed at a certain time.

I've had to rework it a little to accomodate changing hours but it definitely does the trick.

Regards

Nick
 
Upvote 0
Nick,

A small modification of the Barry Houdini formula (without MEDIAN fucntion):

Note: no more smart, but if you want try it.

<b>Excel 2007</b><table cellpadding="2.5px" rules="all" style=";background-color: #FFFFFF;border: 1px solid;border-collapse: collapse; border-color: #A6AAB6"><colgroup><col width="25px" style="background-color: #E0E0F0" /><col /><col /><col /><col /><col /><col /><col /></colgroup><thead><tr style=" background-color: #E0E0F0;text-align: center;color: #161120"><th></th><th>A</th><th>B</th><th>C</th><th>D</th><th>E</th><th>F</th><th>G</th></tr></thead><tbody><tr ><td style="color: #161120;text-align: center;">1</td><td style="text-align: center;;">Start</td><td style="text-align: center;;">End</td><td style=";">Time worked</td><td style="text-align: right;;"></td><td style=";">Range</td><td style="text-align: center;;">08:00</td><td style="text-align: center;;">16:00</td></tr><tr ><td style="color: #161120;text-align: center;">2</td><td style="text-align: center;;">8/3/11 20:03</td><td style="text-align: center;;">8/6/11 17:10</td><td style="text-align: center;;">16:00</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">3</td><td style="text-align: center;;">8/2/11 09:17</td><td style="text-align: center;;">8/8/11 02:45</td><td style="text-align: center;;">30:42</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">4</td><td style="text-align: center;;">8/4/11 01:39</td><td style="text-align: center;;">8/4/11 12:03</td><td style="text-align: center;;">04:03</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">5</td><td style="text-align: center;;">8/2/11 00:22</td><td style="text-align: center;;">8/2/11 13:35</td><td style="text-align: center;;">05:35</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">6</td><td style="text-align: center;;">8/3/11 08:20</td><td style="text-align: center;;">8/7/11 13:25</td><td style="text-align: center;;">23:39</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">7</td><td style="text-align: center;;">8/1/11 18:40</td><td style="text-align: center;;">8/7/11 06:37</td><td style="text-align: center;;">32:00</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">8</td><td style="text-align: center;;">8/4/11 17:12</td><td style="text-align: center;;">8/5/11 01:33</td><td style="text-align: center;;">00:00</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">9</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">10</td><td style="text-align: center;;">************</td><td style="text-align: center;;">************</td><td style="text-align: right;;"></td><td style=";">******</td><td style=";">******</td><td style=";">******</td><td style=";">******</td></tr></tbody></table><p style="width:4.2em;font-weight:bold;margin:0;padding:0.2em 0.6em 0.2em 0.5em;border: 1px solid #A6AAB6;border-top:none;text-align: center;background-color: #E0E0F0;color: #161120">Sheet42</p><br /><br /><table width="85%" cellpadding="2.5px" rules="all" style=";border: 2px solid black;border-collapse:collapse;padding: 0.4em;background-color: #FFFFFF" ><tr><td style="padding:6px" ><b>Worksheet Formulas</b><table cellpadding="2.5px" width="100%" rules="all" style="border: 1px solid;text-align:center;background-color: #FFFFFF;border-collapse: collapse; border-color: #A6AAB6"><thead><tr style=" background-color: #E0E0F0;color: #161120"><th width="10px">Cell</th><th style="text-align:left;padding-left:5px;">Formula</th></tr></thead><tbody><tr><th width="10px" style=" background-color: #E0E0F0;color: #161120">A2</th><td style="text-align:left">=RANDBETWEEN(<font color="Blue">40756,40760</font>)+RAND(<font color="Blue"></font>)</td></tr><tr><th width="10px" style=" background-color: #E0E0F0;color: #161120">B2</th><td style="text-align:left">=A2+RANDBETWEEN(<font color="Blue">0,5</font>)+RAND(<font color="Blue"></font>)</td></tr><tr><th width="10px" style=" background-color: #E0E0F0;color: #161120">C2</th><td style="text-align:left">=IF(<font color="Blue">NETWORKDAYS(<font color="Red">A2,B2</font>)>1,(<font color="Red">$G$1-$F$1</font>)*(<font color="Red">NETWORKDAYS(<font color="Green">A2,B2</font>)-1</font>),0</font>)+
IF(<font color="Blue">NETWORKDAYS(<font color="Red">B2,B2</font>)>0,IF(<font color="Red">(<font color="Green">MOD(<font color="Purple">B2,1</font>)>F$1</font>)*(<font color="Green">MOD(<font color="Purple">B2,1</font>)<G$1</font>),MOD(<font color="Green">B2,1</font>),IF(<font color="Green">(<font color="Purple">MOD(<font color="Teal">B2,1</font>)<=F$1</font>),F$1,G$1</font>)</font>),G$1</font>)-
IF(<font color="Blue">NETWORKDAYS(<font color="Red">A2,A2</font>)>0,1,0</font>)*IF(<font color="Blue">(<font color="Red">MOD(<font color="Green">A2,1</font>)>F$1</font>)*(<font color="Red">MOD(<font color="Green">A2,1</font>)<G$1</font>),MOD(<font color="Red">A2,1</font>),IF(<font color="Red">(<font color="Green">MOD(<font color="Purple">A2,1</font>)<=F$1</font>),F$1,G$1</font>)</font>)</td></tr></tbody></table></td></tr></table><br />

Markmzz
 
Upvote 0

Forum statistics

Threads
1,224,596
Messages
6,179,807
Members
452,944
Latest member
2558216095

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