Time Calculation Question

spyldbrat

Board Regular
Joined
May 5, 2002
Messages
211
Office Version
  1. 365
I am trying to create a formula so that it calculates time to the hundredths of a minute based on the conditions below. The best someone was able to do was to give the result in 3 separate columns - 1 column displayed the hours, one displayed the minutes and one displayed the total hours. However, I really need the result to to be in 1 column.

If L = 0 then 0

If P = F then subtract I from H and display in 100ths of a minute

If P is > F, then subtract I from AC1 (midnight) and display in 100ths of a minute

This is the formula I currently have. I couldn’t figure out how to add the second condition.

=IF(L2=0,0,IF(P2=F2,L2,HOUR($AC$1-H2)+MINUTE($AC$1-H2)/60))
 
The formula works fine for me, with only a screen capture to go on best guess would be that the date in P2 is 9 July and not 7 September.
 
Upvote 0

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Here is a revision that rounds according to the rules mentioned...
MrExcel20200915.xlsx
FGHIJKLMNOPQRSTU
1Date Shift StartTime InTime OutLunch (decimal hours)Total Hrs Worked (rounded 1/4 h)Date Shift EndTotal Hours Worked (decimal)Hours Current DayHours Next DayHours Var
29/7/202016:3220:3304.009/7/20204.024.020.00-0.02
39/6/202016:3220:0903.509/6/20203.623.620.00-0.12
49/12/202022:361:1802.759/13/20202.701.401.300.05
Sheet1
Cell Formulas
RangeFormula
Q2:Q4Q2=IF(ROUND(((P2+I2)-(F2+H2))*24,2)-J2>=0,ROUND(((P2+I2)-(F2+H2))*24,2)-J2,"not possible")
R2:R4R2=IF(F2=P2,Q2,IF(P2=F2+1,(P2-(F2+H2))*24,IF(P2>F2+1,"shift too long",IF(P2<F2,"not possible"))))
S2:S4S2=IFERROR(Q2-R2,"")
K2:K4K2=IF(MOD(Q2,0.25)<0.125,FLOOR(Q2,0.25),CEILING(Q2,0.25))
U2:U4U2=IFERROR(K2-Q2,"")
 
Upvote 0
@jasonb75 the date in P is set to the correct format of MM-DD-YY. There is a formula in P that increases the date from F by 1 if the time out is greater than the time in: =IF(I2<=H2,F2+1,F2). I am not sure if this can be causing the issue? I am also including a screen shot of the formatting from P. The same format also exists in F.
1601299807319.png


Currently the formulas are the following:
Q: =ROUND(DOLLARFR(MOD(((P2+I2)-(F2+H2))-J2,1)*24,100),2)
R: =ROUND(DOLLARFR(MOD((MIN(P2+I2)-(F2+H2))-J2,1)*24,100),2)
S: =IF(P2>F2,R2-Q2,"0.00")

The formula in R only partially works. It does not calculate up to midnight in R if the shift ends on the next day:

1601300176845.png
 
Last edited:
Upvote 0
The formula in R is probably not working because part of it is missing, if I use the longer version from my post it works fine.

=ROUND(DOLLARFR(MOD((MIN(P2+I2,F2+1)-(F2+H2))-J2,1)*24,100),2)

Also, you don't need all of that if S2, the short version in my post works just as well.
 
Upvote 0
When I replaced S2 with above, the time is calculating for the shifts that cross midnight calculate correctly. BUT, now it seems it's not calculating correctly for the shifts that DON'T cross midnight?

1601308221549.png
 
Upvote 0
Sorry, that was my bad. I meant the shorter version in my earlier post.
=Q2-R2
The IF part of your original formula in S2 is not needed. Also note that it is Q2-R2, not R2-Q2 as you have in your formula.
 
Upvote 0
Do your time columns have dates hidden by formatting?

This is the only reason I can think of for the formula to fail, I get the correct results using the data from your screen captures.

If this is the cause of the error then it would have been immediately apparent if you had followed the request in post 7 and used XL2BB to post your data examples instead of screen captures (which only allow us to see the visual data, not the actual data).
 
Upvote 0

Forum statistics

Threads
1,214,376
Messages
6,119,174
Members
448,870
Latest member
max_pedreira

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