Specific overtime calculation - excel

I'm working on a simple timesheet that should calculate overtime1 and overtime2, I just cant figure out a good way to fix it.
Normal workday on 8hrs from 07:00 to 17:00 give no overtime (eg 07:00 to 16:00 or 08:00 to 17:00), but when time exceeds 8 hours I would like to get the exceeding hours in a cell.
My business rules are:
1) Any work greater than 8 hours between the hours of 06:00 to 20:00 get paid as overtime1.
2) Any work less than 8 hours will not generate any overtime2 even if after 20:00
3) Any work performed earlier than 06:00 or later than 20:00 get paid at the overtime2 rate.
Example 1: Working from 07:00 to 18:00 would get a value of 3 hours of overtime1
Example 2: Working from 14:00 to 22:00 would generate 0 hours of overtime2.
Example 3: Working 05:00 to 21:00 would give overtime1 6 hours and overtime2 2 hours (1 hour before 06:00, 1 hour after 20:00).

This is a pretty easy problem to solve if your data is laid out smartly. With column A as clock in time and column B as clock out time, use this formula as a helper to determine if you should use the clock in time or your base of 06:00:
=IF(A1-FLOOR(A1,2)<6/24,6/24,A1-FLOOR(A1,2))
Then use this formula to determine if you should use clock out time or 20:00:
=IF(B1-FLOOR(B1,2)>20/24,20/24,B1-FLOOR(B1,2))
Then you subtract the two to get fractions of a day, multiply by 24 to convert to hours, then subtract 8 to get hours of overtime1. Combined in a super formula it looks like this in C1:
OT1: =IF(OR(ISBLANK(A1),ISBLANK(B1)),"",(IF(B1-FLOOR(B1,2)>20/24,20/24,B1-FLOOR(B1,2))-IF(A1-FLOOR(A1,2)<6/24,6/24,A1-FLOOR(A1,2)))*24-8)
Remember, Excel formats dates where 1 = 24 hours. Also, I added in an OR(ISBLANK(A1),ISBLANK(B1)) statement to make sure you get a null string if one of the values is blank.
Starting on the overtime2, you need to split it into two parts: before 06:00 and after 20:00. The first part checks if the clock in time is earlier than 06:00 and if so figures out how many hours. The formula ultimately ends up being:
=IF(IF(A1-FLOOR(A1,2)<6/24,6/24,A1-FLOOR(A1,2))<=6/24,(6/24-(A1-FLOOR(A1,2)))*24,0)
For after 20:00, the same pattern is used. Figure out how many parts of a day were logged after 20:00. The final formula ends up being:
=IF(IF(B1-FLOOR(B1,2)>20/24,20/24,B1-FLOOR(B1,2))>=20/24,((B1-FLOOR(B1,2))-20/24)*24,0)
Finally, to figure out the total number of overtime 2, just add the two formulas together in D1:
OT2: =IF(OR(ISBLANK(A1),ISBLANK(B1)),"",IF(IF(A1-FLOOR(A1,2)<6/24,6/24,A1-FLOOR(A1,2))<=6/24,(6/24-(A1-FLOOR(A1,2)))*24,0)+IF(IF(B1-FLOOR(B1,2)>20/24,20/24,B1-FLOOR(B1,2))>=20/24,((B1-FLOOR(B1,2))-20/24)*24,0))

It's just about getting the logic right and understanding that Excel treats 07:00 as a decimal equal to 7/24, for example.
OT1
=IF(NOT(AND(Sheet1!$A2>=7/24,Sheet1!$B2<=17/24)),MIN(20/24,Sheet1!$B2)-Sheet1!$A2-9/24,0)
OT2
=IF(MIN(20/24,Sheet1!$B2)-Sheet1!$A2-9/24,MAX(B2-20/24,0),0)

Related

I produce 365 items in one hour and 4000 in 10.95 hour how to set when it will complet by time

Let's say i logged in today 9:00 AM and end up 5:00 PM i have to produce 4000 items i know it will exceed the time because my software will stop working at 5 PM so tomorrow when i start working again what would be date and time of completion work
What i did
bring working hour =SUM(B2-A2)
total complete work=ROUND(D2/C2, 2)
If i understood correctly you can use the simple difference of times and correct formatting for the time cells to get the remaining hours
The Formula in cell C5 is simple =C1-C3
The formatting applied to the cells is as below
10.95 hours is equal to 10 hours and 57 (95% of 60) minutes
You can write 10:57:00 instead of 10.95
To convert the time to again a number you can divide the time by 0.041666667 and set the format to general

Excel - Placing values that fall within a certain time range

I have the following data on duration of particular services.
A B C D
Usage Start (Local time) Start Time Usage Until (Local time) End Time
03.03.2018 10:00 12:00:00 AM 03.03.2018 00:00 1:00:00 AM
03.03.2018 00:00 1:00:00 AM 03.03.2018 00:00 2:00:00 AM
03.03.2018 16:30 1:00:00 AM 03.03.2018 00:00 3:00:00 AM
And I want to count the number of times a timing falls within a certain range(eg. 00:00 - 01:00)
Start End Counts
00:00 01:00 1
01:00 02:00 2
02:00 03:00 1
03:00 04:00
04:00 05:00
05:00 06:00
What formula should I use and how do I apply it?
I have tried this
=COUNTIFS($B$2:$B$566,">="&A2,$D$2:$D$566,"<"&B2)
And this
=SUMPRODUCT(($B$2:$B$566>= A2)*($D$2:$D$566< B2))
But it doesn't account for more than 24 hour duration (Eg.3/3/2018 1:00 PM - 4/3/2018 2:00 PM, 25 hours)
It looks like you're ignoring the time portion in Columns A and C. Assuming your start/end hour bins are in columns F and G, the formula below will give you the number of times that an event passed through your first hour bin (you have to enter it as an array formula--ctrl+shift+enter). Fill down for subsequent hour bins.
=SUM(($B$2:$B$4<F2+TIME(0,30,0))+($D$2:$D$4>F2+TIME(0,30,0))+INT($C$2:$C$4)-INT($A$2:$A$4)-1)
This will count an event in an hour bin if the event is active at the half-hour mark.
If the event needs to cover the entire time bin, use this formula (again with ctrl+shift+enter):
=SUM(($B$2:$B$4<=F2)+IF(G2>F2,($D$2:$D$4>=G2))+INT($C$2:$C$4)-INT($A$2:$A$4)-1)
Was a bit more complicated than I expected, but I got it to work.
Though before we start, you need to format your table a little. You
can't have date and time in the same cell (as excel has trouble
recognizing storing two formats in 1 cell).
Instead format your table
like so:
Next we should create some hidden rows (technically you can stick what I'm about to do in 1 giant formula, but for sake of clarity I prefer hidden rows)
First we focus on the time difference in hours. Creating the two following columns
Also, make sure, you set the format in these newly added rows to
number. Technically it will work without it, but it will look
confusing to human eye
In the Time defference we use the following formula
=ABS(F2-C2) * 24
In the overnight h column:
=IF(C2>F2, 24-G2, G2) This is utilized that we properly count with transition dates (eg. 23:00 1/1/18 -> 01:00 2/1/18) we don't want to add the extra 24 hours in this case.
That would be the hours fully working, but we also need to ensure the
formula works, when there's more than one night of difference (eg.
1/1/18 -> 3/1/18)
Next, we add these these two rows
In the date difference column, as the column name suggests
=DATEDIF(A2, D2, "d") * 24
Last but not least, the overnight delta is basically the same principle as overnight h, but with dates instead of hours
So now, if we have hidden the rows, added the following formula to result =H2+I2-J2 we get our sought after table:
Which corresponds with the expected result! :)
EDIT: If you don't want to take hours into cosnideration and only count how many times an interval of 24 hours has expired use the following formula
=IF(C2>F2, DATEDIF(A2, D2, "d")-1, DATEDIF(A2, D2, "d"))
(under presumption c2,f2,a2,d2 are in the columns as in my original table i provided)

Day and night time calculation in Excel sheet

In MS Excel sheet I want to calculate the time I work in the day hours i.e. the hours between sunrise and sunset, and any hours after sunset.
An example might be that I start work at 06:00 am and finish at 09:00 pm.
Sunrise is 07:00 am and sunset is 06:30 pm.
The total time worked all day would be 15 hours.
Time worked during the day (between sunrise and sunset) would be 11 hours and 30 minutes.
Time worked at night would be 3 hours and 30 minutes.
Here is my simple solution :)
Just copy and paste the formulas in E5 and F5 and drag them down to calculate the time as per your requirement
Formula in E5 is:
=IF(AND(B5<$C$1;C5>=$G$1);$G$1-$C$1;IF(AND(B5>=$C$1;C5<$G$1);C5-B5;IF(AND(B5<$C$1;C5<$G$1);C5-$C$1;$G$1-B5)))
Formula in F5 is:
=C5-B5-E5
It is important to note that my solution covers all four possibilities which are:
1. Start work at night and end at night
2. Start work at day and end at day
3. Start work at night and end at day
4. Start work at day and end at night
:)
Below is what I think you want to achieve.
Since I have included sunrise and sunset as columns it means that you can add another column Date and then you can track each new day as a new row; since sunrise and sunset change each day you cannot simply have one cell to set the times for these for all your data.
The formulas:
A2
06:00:00
B2
21:00:00
C2
07:00:00
D2
18:30:00
E2
=IF(B2>D2,D2,B2)-IF(A2<C2,C2,A2)
F2
=(B2-A2)-E2
Notice that I have written the times in 24 hour clock.
This is important since Excel cannot tell the difference between 07:00 if it is AM or PM and you cannot pass AM or PM in the cells.
The formula in E2 will check if you have started before sunrise or not. If you have started before sunrise then it will just use the sunrise time.
Then it will do the same check for sunset; using sunset if you have worked after sunset.
After that it will just subtract the two numbers and return the time worked.
F2 will just simply subtract the start and end time to work out total time worked all day and will then just subtract the time worked in the day.

Reply Time Issue

I'm from Turkiye and my level is intermediate. I reply mails in 8 hours at work. My question is about time calculation.
Conditions
1. Our work starts at 09:00 and finishes at 18:00.
2. Mails must be replied in 8 hours.
3. Mails must be replied only between 09:00 and 18:00.
4. We don't work between 18:00 and the next day 09:00.
So these period doesn't count in the calculation. This is the most critical part also.
My Excel File. I explained all conditions in the workbook.
So we can break down your all condition to basically two categories. One, where (Mail Received Time + 8 Hours) is less than or equal to 18:00 Hrs, other is where it falls beyond 18:00 Hrs.
Use the formula in the Reply Deadline with formula column and drag it down to get the desired answer
=IF((A7+"8:00"<=TIME(18,0,0)),MAX(A7,"9:00")+"8:00",MIN(A7,"18:00")+"23:00")
Explanation
IF condition checks if the mail received time + 8:00 hrs is less than or equal to 18:00 hrs and returns a TRUE or FALSE value
Output: =IF((FALSE),MAX(A7,"9:00")+"8:00",MIN(A7,"18:00")+"23:00")
If TRUE the time is added by 8:00 hrs to give the deadline. MAX has been used to eliminate any mail received time that is before 9:00 Hrs as in 08:28 Hrs
If FALSE the time is added by 23:00 hrs. This is because 8:00 hrs is the normal deadline and remaining 15:00 hrs is accounted for time we don't work i;e from 18:00 Hrs to next day 9:00 Hrs. MIN is used to consider when the mail received time is less than 18:00 hrs.
Let me know if I can make it more clear.
EDIT
Here is my sample file with solution formulas embedded.
Please try the below formula,
=IF(OR(A2<TIME(9,0,0),A2>TIME(18,0,0)),TIME(17,0,0),IF(A2+TIME(8,0,0)<=TIME(18,0,0),A2+TIME(8,0,0),A2+TIME(23,0,0)))
This formula consists of 2 IF conditions.
The first IF checks if the time falls in non-working hours (between 18:00 and 9:00). If so, the time is calculated as 17:00. If the time falls in the working range, the next IF condition adds 8:00 hours or 23:00 accordingly. (23:00 hours for overlapping period). Hope this helps.
excelevator solved the problem on reddit also.
https://www.reddit.com/r/excel/comments/65l25n/reply_time_calculation_issue/

Excel how get number of hours in a time interval?

I have 2 columns with:
Night shift start: 19:00
Night end: 04:00
And I have some date columns with for each day..
Work started: 07:30
Worked ended: 22:00
I want to get the number of hours as a decimal that is between the night shift start and night end. I need to calculate the number of "night shift hours" for worked hours.
From comment: I do not want to get the total number of hours. I want to calculate the number of "night shift hours" and that is hours between 19:00-04:00
=IF(B1-A1 < 0, 1-(A1-B1),( B1-A1))
Assuming that cell A1 contains start, B1 contains end time.
Let me know, if it helps OR errors.
Time without date is not enough to do the subtraction considering the start can be the night before today.
Are you OK to try VBA?
EDIT: The formula is meaningful within 12 hour limit. I will see if it can be made simpler.
Given start time in B5 and end time in C5 this formula will give you the decimal number of hours that fall in the range 19:00 to 04:00
=MOD(C5-B5,1)*24-(C5<B5)*(19-4)-MEDIAN(C5*24,4,19)+MEDIAN(B5*24,4,19)
format result cell as number
just substract the two dates to get the difference in days, and multiply by 24 to get the difference in hours
=(B1-A1)*24
this is correct when both B1 and A1 contain a datetime value, but in case your cells contain just a time value, with no day value, and given that the calculation spans the night (there is a day change in between) you need to add one day to the difference:
=IF(B1<A1,1+B1-A1,B1-A1)*24

Resources