Extract time from formula

elynoy

Board Regular
Joined
Oct 29, 2018
Messages
160
Office Version
  1. 365
  2. 2021
  3. 2016
Platform
  1. Windows
Hello.

I'd like to know if it's possible to extract tiome from a fórmula.

I'll try to explain:

I have a formula wich I get the total hours in a day, night hours based on a specific time, and the amount of hours in the day as normal hour so to speak.

the formula I have is this one:
Excel Formula:
=(($C40>$D40)*MED(0;$D40-$AP$19;MED($AP$19;$AP$18))+MÁXIMO(0;MÍNIMO($AP$18;$D40+($C40>$D40))-MÁXIMO(1/4;$C40)))

with this for the rest:
Excel Formula:
=RESTO(D40-C40;1)

And this one
Excel Formula:
=O40-P40

That formula gets me the amount of time and extra hours on those 24 hours.

what I'd liiek to know if it's possible to make it "extract" 8 hours from whatever start hour I start to work.

exemple on this table:

work start time
08:00​
09:00​
10:00​
11:00​
12:00​
13:00​
14:00​
15:00​
16:00​
17:00​
18:00​
19:00​
20:00​
Regular hour price
4,99 €
4,99 €
4,99 €
4,99 €
4,99 €
4,99 €
4,99 €
4,99 €
4,99 €
7,49 €
7,49 €
7,49 €
7,49 €
74,87 €
Percentage based on hours worked (8+)
50%
50%
50%
50%
Number of hours worked
1​
2​
3​
4​
5​
6​
7​
8​
9​
10​
11​
12​
work start time
20:00​
21:00​
22:00​
23:00​
00:00​
01:00​
02:00​
03:00​
04:00​
05:00​
06:00​
07:00​
08:00​
Regular hour price
4,99 €
6,24 €
6,24 €
6,24 €
6,24 €
6,24 €
6,24 €
6,24 €
6,24 €
9,98 €
9,98 €
7,49 €
7,49 €
89,85 €
Percentage based on hours worked (8+)
75%+25%
75%+25%
50%
50%
Number of hours worked
1​
2​
3​
4​
5​
6​
7​
8​
9​
10​
11​
12​
work start time
12:00​
13:00​
14:00​
15:00​
16:00​
17:00​
18:00​
19:00​
20:00​
21:00​
22:00​
23:00​
00:00​
Regular hour price
4,99 €
4,99 €
4,99 €
4,99 €
4,99 €
4,99 €
4,99 €
4,99 €
4,99 €
9,98 €
9,98 €
9,98 €
9,98 €
84,83 €
Percentage based on hours worked (8+)
75%+25%
75%+25%
75%+25%
75%+25%
Number of hours worked
1​
2​
3​
4​
5​
6​
7​
8​
9​
10​
11​
12​


The table, after 8 working hours the percentage is 50% higher day extra hour or 25% higher if it's night shift. If it's night shift it has an extra 75% if it's extra hour (after 8+ hours worked)

edit: I forgot to mention that the night shift starts at 21:00 untill 06:00.

I'm sorry if it's confusing, but I'm having a hard time trying to figure how this might work.

I tried making the calculation manual, but then I get stuck since I cant get the right times needed for each percentage based oh the amount of hours.

And, I dont even know if it's possible to achieve this.

Either way, thanks in advance if someone is whilling to help me in a way of doing it.

eLy
 
How can I accomplish it? can I split the formulas? I have no problem is using extra cells and hide then.

Here is one example of using hidden columns. I did this quickly, so if there are errors from the previous version you will need to find and fix them yourself.
tmp.xlsm
ABCDEFGHIJKLMNOPQRSTUV
1Settings(named ranges removed)
2BaseRate10€ /hr
3OTFactor50%
4NightShiftFactor25%
5NightOTFactor75%
6Night Shift Start21:00
7Night Shift Stop6:00
8
9Hidden ColumnHidden ColumnHidden ColumnHidden ColumnHidden ColumnHidden Column
10StartUser Entered StopNext DayHours of workDay Rate HoursNight Rate HoursTotal OTDaytime OTNight OTNormal PayOT PayNight PayNight OT BonusTotal PayMath CheckStop (Adjusted)Night Shift StartNight Shift StopOT StartNight OT Start
1100000000,000,000,000,000,00TRUE1/0/1900 0:000:001/0/1900 6:008:008:00
128:0020:00012120440120,0020,000,000,00140,00TRUE1/0/1900 20:0021:001/0/1900 20:0016:0021:00
1320:008:0011239422120,0010,0022,5015,00167,50TRUE1/1/1900 8:0021:001/1/1900 6:004:004:00
1412:000:0011293413120,005,007,5022,50155,00TRUE1/1/1900 0:0021:001/1/1900 0:0020:0021:00
1512:000:0011293413120,005,007,5022,50155,00TRUE1/1/1900 0:0021:001/1/1900 0:0020:0021:00
1621:006:00190910190,000,0022,507,50120,00TRUE1/1/1900 6:0021:001/1/1900 6:005:005:00
T2 X
Cell Formulas
RangeFormula
C11:C16C11=IF(B11<$A11,1,0)
D11:D16D11=(R11-A11)*24
E11:E16,H11:H16E11=D11-F11
F11:F16F11=IF(TRIM(A11)&TRIM(B11)="",0,ROUND(IF((T11-S11)*24<0,0,(T11-S11)*24),2))
G11:G16G11=MAX(0,D11-8)
I11:I16I11=IF((T11-S11)*24<0,0,IF((T11-V11)*24<0,0,(T11-V11)*24))
K11:K16K11=D11*$B$2
L11:L16L11=H11*$B$3/100*$B$2
M11:M16M11=F11*$B$4/100*$B$2
N11:N16N11=I11*$B$5/100*$B$2
O11:O16O11=SUM(K11:N11)
Q11:Q16Q11=D11=E11+F11
R11:R16R11=IF(C11=1,B11+1,B11)
S11:S16S11=IF(C11=1,IF(A11>$B$6,A11,$B$6),IF(A11>=$B$7,$B$6,A11))
T11:T16T11=IF(C11=1,IF(R11<$B$7+1,R11,$B$7+1),IF(AND(A11>=$B$7,R11 > $B$7),R11,$B$7))
U11:U16U11=A11+TIME(8,0,0)
V11:V16V11=IF(U11<S11,S11,U11)
 
Upvote 0

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Can you tell me how I can add more shifts to your formula like this:

Testes.xlsm
CDEFGH
4START 1STOP 1START 2STOP 2START 3STOP 3
508:0012:0016:0020:0021:0000:00
Jan


I tried to add your formulas to more cells and then make them SUM but then It wont get extra hours since the shifts are split.
 
Upvote 0
Can you tell me how I can add more shifts to your formula like this:
You mean without tossing everying done up until now into the rubbish bin and starting from scratch? I'm not sure it can be done.

I'd suggest using 3 rows.
tmp.xlsm
ABCDEFGHIJKLMNO
10StartUser Entered StopNext DayHours of workDay Rate HoursNight Rate HoursTotal OTDaytime OTNight OTNormal PayOT PayNight PayNight OT BonusTotal Pay
118:0012:00044000040.000.000.000.0040.00
1216:0020:00044000040.000.000.000.0040.00
1321:000:00130300030.000.007.500.0037.50
14117.50
T2 X
 
Upvote 0
I understand.

Shoul've said it before.
Using 3 rows wont work since it wont count the OT cells still.

Thank you for your help with all of this!
Best regards!
 
Upvote 0
Is it possible to convert it to time instead of number as cell format? If I start at 08:00 and end ad 16:30 it gives me 8.5 hours instead of 8.30
 
Upvote 0
Divide it by 24 and format the cell as time
 
Upvote 0
Is it possible to convert it to time instead of number as cell format?
Is it possible? Yes it is possible. In theory you can do as @MARK858 says and divide by 24 and reformat to display as time.

But as a practical 'how-to' matter there are some significant caveats that may require you to modify several other formulas. I don't know what your worksheet looks now, but chances are it is not just that one cell you must modify. You will likely need to do the divide-by-24 conversion in formulas in several cells.

Bear in mind that dividing by 24 changes the cell value. Yes, the cell can be then reformatted to display as 08:30 but the underlying value is still changed from 8.5 to 0.35417 (8.5 / 24 = 0.35417). So if another formula was trying to multiply 8.5 hr x 4.99 €/hr to calculate pay it will not produce the correct result until you go fix that formula. This means that if you make the change (by dividing by 24 and reformatting as time) you will need to follow through and adjust the other formulas that depend on the cells you performed the divide-by-24 operation on, and test with various values until you are sure that everything is producing correct results again.
 
Upvote 0
Thanks for the answers.

I added a new column next to them and divided it by 24 but I left the calculations as normal number. I just need it to show the time instead of a number.

So in theory everything sould work as intended and the formulas should work the same, I just hid the number and show the time and let the formulas work as number as you said.

Thanks for everything by the way.
 
Upvote 0
there's a problem but I dont know how to explain.
I have the conditional format do make the cells with 0 value stick to the color like if it's empty but I still get 0 in there and I get the #### in some cells as well but not all of them.
Cell Formulas
RangeFormula
E5:E10E5=IF(D5<$C5,1,0)
F5:F10F5=(IF(E5=1,D5+1,D5)-C5)*24
G5:G10,I5:I10,K5:K10,M5:M10,O5:O10G5=F5/24
H5:H10,N5:N10H5=F5-J5
J5:J10J5=IF(TRIM(C5)&TRIM(D5)="",0,ROUND(IF((IF(E5=1,IF(IF(E5=1,D5+1,D5)<$AF$18+1,IF(E5=1,D5+1,D5),$AF$18+1),IF(AND(C5>=$AF$18,IF(E5=1,D5+1,D5)>$AF$18),IF(E5=1,D5+1,D5),$AF$18))-IF(E5=1,IF(C5>$AF$17,C5,$AF$17),IF(C5>=$AF$18,$AF$17,C5)))*24<0,0,(IF(E5=1,IF(IF(E5=1,D5+1,D5)<$AF$18+1,IF(E5=1,D5+1,D5),$AF$18+1),IF(AND(C5>=$AF$18,IF(E5=1,D5+1,D5)>$AF$18),IF(E5=1,D5+1,D5),$AF$18))-IF(E5=1,IF(C5>$AF$17,C5,$AF$17),IF(C5>=$AF$18,$AF$17,C5)))*24),2))
L5:L10L5=MAX(0,F5-$AF$6)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
W4:W35,N4:O35Cell Value=0textNO
J4:K35Cell Value=0textNO
V5:V35,L5:M35,E5:I35Cell Value=0textNO
 
Upvote 0
Cant edit the post above.

if I enter 15:01, or something higher then 15:00, it works. but it only show 07:59 as time and not 08:00
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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