I'm making something in excel which calculates my hours I work a week/month, when a number gets to 30.60 (two shifts which when finishing on the half an hour) it calculates it as 30.60*wage=not the right pay.
so far I have =ROUND(SUM(C6:I6),0) which rounds up the number, which works fine until I have another day which I work till half an hour then it will just show 16 or so.
As you can see here, it calculates it fine until I work 7.30 hours on a wednesday, the total shows 23.00 instead of 23.30.
How can this be done.
Thank you.
your problem is with excel understanding of your "hours". When you write 7.30 you mean 7 hours 30 minutes = 7.5 hours. But excel understands that as 7 hours and 30/100 of hour = 18 minutes. The easiest solution would be to use 7,5 for 7 hours 30 minutes.
(for sake of checking the question off the unanswered I copied my comment)
If you don't want to use 7.5 (Seven-and-a-half-hours) or 7:30 (7 hours, 30 minutes - but remember to multiply this by 24, since Excel stores this as the fraction of a day, 0.3125) then you can use INT and MOD:
=INT(C6)+(MOD(C6,1)/0.6)
The first part, INT(c6) will give you the Integer part (i.e. whole hours) which we don't want to scale/skew.
The second part has 2 stages. First, MOD(c6,1) will give us the Decimal part of the number (i.e. 7.3 will become 0.3) and the second part is to divide by 0.6 to convert from "fake-minutes" to "fraction-of-real-hour"
Finally, since you want to apply the formula to an array of cells, you will need to swap from SUM to SUMPRODUCT:
=SUMPRODUCT(INT(C6:I6)+(MOD(C6:I6,1)/0.6))
But, overall, best option is to use 7:30 and set Data Validation only allow actual Time values in that field.
{EDIT} Of course, this will give your output with 0.5 for 30 minutes. If you want to reverse back to 0.3 for 30 minutes (although, I can scarcely fathom why) then you need to run the same calculation in reverse:
=INT(SUMPRODUCT(INT(C6:I6)+(MOD(C6:I6,1)/0.6))) + 0.6*MOD(SUMPRODUCT(INT(C6:I6)+(MOD(C6:I6,1)/0.6)),1)
Related
I have a problem where I am trying to calculate in Excel if any part of a provided work duty time period is contained within a user defined period which specifies the night working hours e.g. 2330-0559 or 0000-0630.
If I provide a work duty time I want and any part of the duty is within the specified period it needs to be identified. E.g. 2230-0630 duty time is within both examples above.
I can tried a few different solutions and still not got the right way solve it.
Maybe someone can help. I also know that 24:00 in excel is used for midnight at the end of the day and 00:00 is used for midnight starting the day as excel works from 0-1 as part of the day.
=OR(MOD(A5,1)>$E$2,MOD(A5,1)<$F$2)
I would work with the number of minutes as decimal and with it make a valid range from "Duty start time" and "Duty end time".
Check if you can make any sense out of this:
Here the example:
https://drive.google.com/file/d/1O1B76srlY8sYQHsV_TiZVzi-7B_18eSj/view?usp=sharing
Update: Sorry for the lack of explanation. Here I try my best to clarify how I did it.
Conversion
First of all I try to convert any time into minutes, so 00:00 is 0 minutes, 01:00 is 60 minutes, 24:00 (excel shows 00:00) is 1440 minutes, 25:00 (excel shows 01:00) is 1500 minutes.
That conversion I do with CONVERT(E2,"day", "mn"), which does convert from day to minutes.
Range Normalization and inclusion
Now every range has to be normalized, that means the "End" has to be always bigger than "Start". For 00:00 to 06:00 this works fine, but for 22:00 to 06:00 it needs to be tweaked. So if "Start" is bigger than "End" then I add 1440 mins (24 hours) to "End". That I do with IF(A6>B6, 1440,0).
You then need to see if any "Duty range" contains the "Night range". That normally is done with the formula if (DutyEnd > NightStart AND DuttyStart < NightEnd) then TRUE.
Challenge 1
That was the main concept. But then if you try to compare a range like 00:00-06:00 contained in 24:00-06-00 it does not work. And that is because the converted minutes are 0-360 and 1440-1830, they don't contain each other.
In E3 to fix this I cut down 1440 with modulo (MOD()), then MOD(1440, 1440) = 0. So even if you use values like 25:00 or 52:00, they will be cut down to the smallest amount of minutes. E.g. 25:00 (1500 mins) = 1:00 = 60 mins, 52:00 (3120 mins) = 4:00 = 240 mins
Challenge 2
We have yet another challenge, the possible comparisons are as follows:
00:00-06:00 contained in 00:00-06:00 which in minutes is 0-390 contained in 0-390
00:00-06:00 contained in 22:00-06:00 which in minutes is 0-390 contained in 1320-1830
22:00-06:00 contained in 00:00-06:00 which in minutes is 1320-1830 contained in 0-390
These last two will not match. So that is why in the "Contains" column (E.g.: E6) I compare against the "Night criteria" - 1400 and + 1400.
Hope it is a bit clear. Let me know otherwise..
UNDERSTANDING DATE AND TIME IN EXCEL
Dates in excel are stored as INTEGERS. They represent the days since 1900/01/1 with that date being 1.
Time is stored as a decimal which represents a fraction of a day. 24 hours is 1, 0.5 is 12 noon. etc.
In other words, everything to the left of the decimal is date and everything to the right is time.
JUST USING TIME AND CROSSING MIDNIGHT
This is problematic from the view point that early morning times are less than the late times of the previous day. The fact of the matter is that they are larger. In our heads we do the mental math of knowing the are the following day but we ignore the date aspect.
A quick way to rectify this is to add the date to your time. Life will become much easier with the math. You may however not want to add full dates to start and end times. WITH THE ASSUMPTION that start and end times are not more than 24 hours the simple work around is is to add 1 to the end time when the end time is less than the start time. This means its the next day.
It the example date you provided, column C was insert to CORRECT the end time. It did the check of end less than start if so add one using the following formula:
=B6+(B6<=A6)
The part in brackets is a logic check. It either evaluates to TRUE or FALSE. When excel runs a boolean (TRUE or FALSE) through a math operator (not a function like sum) it will convert TRUE to 1 and FALSE to 0.
LENGTH
Straight forward math of C minus A since C is always after you start and is the larger of the two numbers.
=C6-A6
CROSSING MIDNIGHT
Need to be a little careful in your definition of crossing midnight when a start time or end time is exactly midnight. Technically speaking you did not cross it if you start or stop on it. The difference is really < versus <= or > versus >=. I will leave that to you to sort out. For the math I used:
=AND(A6<1,C6>=1)
Though I did not use this column for anything else
START CHECK
=OR(A6>$F$2,A6<$G$2)
END CHECK
=OR(B6>$F$2,B6<$G$2)
ANY TIME CHECK
I broke this into three columns. It can be combined into one but wanted to show the working parts. The first check is to see if the start time is before the night start and that the shift end time was after the night start time. The second check was similar for the the fisrt except you want to know if the start time is before the night end time and the shift end time is after the night end time. For the OR case you want to check to see if ANY of columns F through I are true:
COLUMN H
=AND(A6<=$F$2,C6>$F$2)
COLUMN I
=AND(A6<$G$2+1,C6>$G$2+1)
Note the +1 for night end time. This is to reflect that the end time is actually on the following day.
COLUMN J
=OR(F6,G6,H6,I6)
or
=(F6+G6+H6+I6)>=1
Place the above formulas in row 6 and copy down as needed
Well, I think I'm missing something but let's see if this works for you. To make this work:
All hours must be typed in hh:mm format
Night Criteria End must be on a different day. This means it must be over 00:00 or formulas won't work. If you type something
like start criteria=22:00 and night criteria= 23:50, both times
would be in the same day, so formulas won't work
This formulas only work in periods less than 24 hours. If anytime the different between criterias is over 24 hours, formulas won't work
properly.
Now, I replied your data like this:
The trick here is dealing with times without dates. Dates in Excel are înteger numbers and decimal parts are the hours/minutes/seconds. So to compare properly hours like this, you need to add an integer part.
Let me explain. In Excel, 18:00 would be 0,75. And 06:00 would be 0,25. If you try to get the difference between both times, you will get -0,5. In decimal it makes sense, but when trying to convert to time, it makes no sense for Excel. So, as I said before, the trick here is adding integers (in this case, because 06:00 is lower than 18:00, we would add +1), so Excel would make 1,25 - 0,75 = 0,5. And Excel can convert 0,5 to hours, and it will return exactly 12 hours, the right result.
So knowing this, the trick in formulas for your data is comparing ends with starts and add 1 or 2 to compare then properly with your criteria. That way Excel can figure out if a time is later or sooner than a criteria.
All my formulas are these ones:
LENGHT: =IF(B5<A5;B5+1-A5;B5-A5)
CROSS MIDNIGHT: =IF(Y(B5<A5;B5<>0);TRUE;FALSE)
START BETWEEN CRITERIA: =IF(AND(IF(A5<$E$2;A5+2;1+A5)>=1+$E$2;IF(A5<$E$2;A5+2;1+A5)<=$F$2+2);TRUE;FALSE)
END BETWEEN CRITERIA: =IF(AND(IF(B5<$E$2;B5+2;1+B5)>=1+$E$2;SI(B5<$E$2;B5+2;1+B5)<=$F$2+2);TRUE;FALSE)
ANY PART:=IF(OR(E5=TRUE;F5=TRUE;AND(A5<$E$2;A5+C5>1+$F$2));TRUE;FALSE)
Anyways, I uploaded a file to my Gdrive, in case it may be helpful to download and check the formulas.
This is the best I got. Probably there is a better way, but I hope this can help you, or at least, you can adapt it to your needs.
https://drive.google.com/open?id=1nrZKfyUhED_y6iiPRSUwRf7GhJlBYt-O
We're doing an overtime incentive where people can earn raffle tickets based on the number of extra hours they work. They earn one ticket for every seven hours of overtime they work. I've built an excel sheet that I can just import the total hours into to track this, but I'm having trouble with the "number of tickets earned" formula.
I have a column for the number of hours over 40 worked, then a column to convert the hours to a number then divide by seven using: =((C2-INT(C2))*24)/7. Next column, I have =ROUNDDOWN(D2, -0.5) because if they worked 15 hours, it was giving them 2.5 tickets.
The issue I'm running into is that when they worked exactly 7 hours, I get 0 for the =ROUNDDOWN(D2, -0.5) formula. I tried =ROUND(D18, -0.5) but if they worked 6 hours 30 minutes, it gives them one ticket. I'm sure I'm probably missing something simple but is anyone able to help?
You have already used INT, which would be a better option than ROUND or ROUNDDOWN. Also C2-INT(C2) can be simplified to MOD(C2,1):
=INT(24*MOD(C2,1)/7)
Breaking it down:
MOD(C2,1) take the decimal portion of C2 (i.e. Hours, less than 24)
24*MOD(C2,1) convert from fraction-of-day to full hours
24*MOD(C2,1)/7 divide by 7. For 6.5 this gives 0.928... and for 15 it gives 2.142...
INT(24*MOD(C2,1)/7) take only the Integer part. For 6.5 this gives 0, for 15 it gives 2
I think your problem is the -0.5 argument of the ROUNDDOWN function. Why do you want to round to negative one half decimal places?
Just use ROUNDDOWN(D2,0).
Edit: I'm not sure why Agent 7 and Agent 8 have different numbers of tickets if they both worked exactly 7 hours overtime. Is the 7:00 a rounded number?
Assuming overtime is in column C, you could use:
=ROUND((HOUR(C1) + IF(MINUTE(C1)<30,0,1)) / 7, 0)
This should yield the correct number of tickets if you want to round up the hour when they are over 30 minutes. Otherwise, you could just take out the IF / MINUTE section and it will only count complete hours.
let’s say I am getting paid 20$ per hour by by my employer and he wants to calculate hours+minutes (not only hours).
if I just want to calculate hours I will use =x*20 in excel
but I want to calculate hours and minutes, let’s say I worked for 1.30 hours, I can use same formula and write 1.30*20= but this doesn't work
the rate in cents is something like 33 cents, how can I just type something like 1.30 (one hour and 30 min) and get the result calculated according to 20$ per hour.
I don’t want to write in minutes because then each time I have to calculate manually then write and it will be messy.
I want to just type hours and minutes in one filed and get the result based on 20$ per hour on the other field. thanks
I use this formula: =ROUND(HOUR(X) + MINUTE(X)/60;2)*20 where X is the cell with the time
I'd use something like: =(TRUNC(x)+MOD(x,1)/0.6)*20
Trunc(x) = hours
Mod(x,1) = fractional part (0.3)
Convert the Mod value to Minutes by dividing by 0.60
Where x = the hour.minute value. (e.g., 1.3 = 1 hour 30 minutes)
This is probably a really long way to do it.
Take the time, as 1.3 for 1 hour 30 mins, remove the minutes and convert to a number you can multiply by, add the hours back and multiply by the hourly rate.
`=(((Time-INT(Time)) * 100/60) + INT(Time))*20
I need to change a value of time from days:hours:minutes, into either hours with a decimal or minutes. My data comes up as 001:05:46 for example. I am having trouble with the leading zeros confusing excel. Any help would be great!
Assuming that your value to parse is formatted in DDD:HH:MM like 001:05:46... There are a lot of ways to do this but here's a simple one. To convert into hours we need to take the days times 24 hours per day, add the hours, and add the minutes times 1 hour per 60 minutes:
=LEFT(A1,3)*24+MID(A1,5,2)+RIGHT(A1,2)/60
To get this value in terms of minutes we multiply by 60 minutes per hour. A possible modification of the original formula to reach this point would be:
=LEFT(A1,3)*24*60+MID(A1,5,2)*60+RIGHT(A1,2)
I am doing some work in Excel and am running into a bit of a problem. The instruments I am working with save the date and the time of the measurements and I can read this data into Excel with the following format:
A B
1 Date: Time:
2 12/11/12 2:36:25
3 12/12/12 1:46:14
What I am looking to do is find the difference in the two date/time stamps in mins so that I can create a decay curve from the data. So In Excel, I am looking to Make this (if the number of mins in this example is wrong I just calculated it by hand quickly):
A B C
1 Date: Time: Time Elapsed (Minutes)
2 12/11/12 2:36:25 -
3 12/12/12 1:46:14 1436.82
I Have looked around for a bit and found several methods for the difference in time but they always assume that the dates are the same. I exaggerated the time between my measurements some but that roll over of days is what is causing me grief. Any suggestions or hints as to how to go about this would be great. Even If I could find the difference between the date and times in hrs or days in a decimal format, I could just multiple by a constant to get my answer. Please note, I do have experience with programming and Excel but please explain in details. I sometimes get lost in steps.
time and date are both stored as numerical, decimal values (floating point actually). Dates are the whole numbers and time is the decimal part (1/24 = 1 hour, 1/24*1/60 is one minute etc...)
Date-time difference is calculated as:
date2-date1
time2-time1
which will give you the answer in days, now multiply by 24 (hours in day) and then by 60 (minutes in hour) and you are there:
time elapsed = ((date2-date1) + (time2-time1)) * 24 * 60
or
C3 = ((A3-A2)+(B3-B2))*24*60
To add a bit more perspective, Excel stores date and times as serial numbers.
Here is a Reference material to read up.
I would suggest you to use the following:
Combine date to it's time and then do the difference. So it will not cause you any issues of next day or anything.
Please refer to the image with calculations. You may leave your total minutes cell as general or number format.
MS EXCEL Article: Calculate the difference between two times
Example as per this article
Neat way to do this is:
=MOD(end-start,1)*24
where start and end are formatted as "09:00" and "17:00"
Midnight shift
If start and end time are on the same day the MOD function does not affect anything. If the end time crosses midnight, and the end is earlier then start (say you start 23PM and finish 1AM, so result is 2 hours), the MOD function flips the sign of the difference.
Note that this formula calculates the difference between two times (actually two dates) as decimal value. If you want to see the result as time, display the result as time (ctrl+shift+2).
https://exceljet.net/formula/time-difference-in-hours-as-decimal-value
get n day between two dates, by using days360 function =days360(dateA,dateB)
find minute with this formula using timeA as reference =(timeB-$timeA+n*"24:00")*1440
voila you get minutes between two time and dates
I think =TEXT(<cellA> - <cellB>; "[h]:mm:ss") is a more concise answer. This way, you can have your column as a datetime.