Calculate time differences

wtom0412

Board Regular
Joined
Jan 3, 2015
Messages
180
Office Version
  1. 365
Platform
  1. Windows
Hello All,

I am stuck. I need to design a workbook that charges customers based on staff time sheets.

This is a reduced version I am using to work out the formulas before I transfer it into the proper sheet...

Timesheet.jpg

So, if the hours worked are between 6am and 6pm, they are charged at Rate 1, if the hours are after 6pm and before 6am, they are charged at Rate 2.

I have worked out how to calculate the number of hours for Rate 2 (Formula in C3)
Excel Formula:
=IF(A3<A1,(A1-A3)*24,0)+IF(B3>B1,(B3-B1)*24,0)
, but I am having specific difficulty working out how to calculate the hours BETWEEN 6am and 6pm when the hours start before 6am and / or after 6pm.

I hope this all makes sense and you can help me?

Thank you, Toby.
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Taking a different approach, this will do what you need. Hopefully it will make sense but please ask if you need anything explaining.
Book1
ABCDE
26pm - 6am6am - 6pmTotal Hours
37:00 AM8:00 PM2.0011.0013.00
48:00 PM7:00 AM11.000.0011.00
58:00 PM5:00 AM9.000.009.00
68:00 AM2:00 PM0.006.006.00
Sheet3
Cell Formulas
RangeFormula
C3:C6C3=E3-D3
D3:D6D3=MOD(MEDIAN(B3,0.25+(A3>B3),0.75)-MEDIAN(A3,0.25,0.75),1)*24
E3:E6E3=MOD(B3-A3,1)*24
 
Upvote 0
Solution
T
Taking a different approach, this will do what you need. Hopefully it will make sense but please ask if you need anything explaining.
Book1
ABCDE
26pm - 6am6am - 6pmTotal Hours
37:00 AM8:00 PM2.0011.0013.00
48:00 PM7:00 AM11.000.0011.00
58:00 PM5:00 AM9.000.009.00
68:00 AM2:00 PM0.006.006.00
Sheet3
Cell Formulas
RangeFormula
C3:C6C3=E3-D3
D3:D6D3=MOD(MEDIAN(B3,0.25+(A3>B3),0.75)-MEDIAN(A3,0.25,0.75),1)*24
E3:E6E3=MOD(B3-A3,1)*24
Thank you so much, it works exactly like I need it to, I am so appreciative of your time and expertise.

I am not sure I underatnd all of the formulas, but if I may (when I have more time tomorrow), may i study it and ask you any questions?

Cheers, Toby
 
Upvote 0
T

Thank you so much, it works exactly like I need it to, I am so appreciative of your time and expertise.

I am not sure I underatnd all of the formulas, but if I may (when I have more time tomorrow), may i study it and ask you any questions?

Cheers, Toby
Hi Jason,

I think there is a bug? When the times are within the AM to PM band, the calculation results in Zero, which means there is nothing to base the dollar calculation on? I think because the formula in C2 takes the hours worked within that band off the Total Hours worked - if they are the same, the result is zero.

The PM to AM band works correctly.

Thanks again for your help.

Cheers, Toby
 
Upvote 0
It took me a while to figure out where the incorrect result was, I double checked my test sheet several times before finding the problem.

This version looks correct and should get you going. I'll have another look at it at some point because I think that the 6am-6pm formula should be shorter, need to give it a few days to try and forget all of the 'wrong ideas' that are stuck in my mind at the moment before trying again though.
Book1
ABCDE
26pm - 6am6am - 6pmTotal Hours
307:00:0020:00:002.0011.0013.00
420:00:0007:00:0010.001.0011.00
520:00:0005:00:009.000.009.00
608:00:0014:00:000.006.006.00
Sheet2
Cell Formulas
RangeFormula
C3:C6C3=E3-D3
D3:D6D3=MOD(IF(A3>B3,MOD(B3-A3,1)-(MEDIAN(B3+1,1.25,0.75)-MEDIAN(A3,1.25,0.75)),MEDIAN(B3,0.25,0.75)-MEDIAN(A3,0.25,0.75)),1)*24
E3:E6E3=MOD(B3-A3,1)*24
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,739
Members
448,989
Latest member
mariah3

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