Assume I have such data:
29.10.2014 19:00 30.10.2014 7:30
29.10.2014 23:00 29.10.2014 18:00
30.10.2014 9:00 30.10.2014 23:15
31.10.2014 18:49 1.11.2014 7:15
How to get that time which is between 22:00 to 6:00. Like first example row 29.10.2014 19:00 30.10.2014 7:30 whole work time is 12:30 (12,5h) and work time between 22-6 is 8:00 (8h). How to get this 8h. Used some searches and find sumproducts, sumifs, countifs but didn't handle them by myself. :/
This article seems to answer your question:
https://office.microsoft.com/en-us/excel-help/calculate-the-difference-between-two-times-HP003056108.aspx
It's easier to calculate the time between 06:00 and 22:00, so assuming start time/date in A2 and end time/date in B2 use this formula to get decimal hours
=(MOD(B2,1)< MOD(A2,1))*(22-6)+MEDIAN(6,22,MOD(B2,1)*24)-MEDIAN(6,22,MOD(A2,1)*24)
That also assumes that end time will either be the same day or the next, is that right?
To get 22-6 time just calculate total time minus the above, so if the above is in C2 use this in D2
=(B2-A2)*24-C2
I assume that your second example is an error because start time/date is after end time/date
Related
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)
I'm trying to create a schedule for myself, but I get confused by seeing the following:
8:00 AM
8:30 AM
9:00 AM
9:30 AM
10:00 AM
10:30 AM
11:00 AM
11:30 AM
12:00 PM
I can never remember whether I am looking at the right block, so I instead want to see this:
8:00 AM to 8:30 AM
8:30 AM to 9:00 AM
9:00 AM to 9:30 AM
9:30 AM to 10:00 AM
Is there an easy way to do this that doesn't involve me typing it into every cell? I want to be able to flash fill the rest of my table, if I can.
(Note: the below is a workaround where I just made a separate column, but it'd be nice if I could do it in one cell.)
Start End
8:00 AM 8:30 AM
8:30 AM 9:00 AM
9:00 AM 9:30 AM
9:30 AM 10:00 AM
10:00 AM 10:30 AM
10:30 AM 11:00 AM
11:00 AM 11:30 AM
11:30 AM 12:00 PM
12:00 PM 12:30 PM
Use this formula:
=TEXT((ROW(1:1)-1)*TIME(0,30,0)+TIME(8,0,0),"hh:mm AM/PM") & " to " & TEXT((ROW(1:1))*TIME(0,30,0)+TIME(8,0,0),"hh:mm AM/PM")
Change each of the TIME(8,0,0) to the first hour you want to show.
If you want a different time block than 30 minutes, change each TIME(0,30,0) to the span desired.
Put 8:00 in A1 and drag down until your schedule ends.
In Another column, C1 in my example, insert the formula =A1+0.5/24 0.5 being a half hour in a 24 hour period. Again, drag down until your schedule ends.
Finally, enter =TEXT(A1,"H:MM AM/PM")&" to "&TEXT(C1,"H:MM AM/PM") in another column, and drag down until your schedule ends.
*If you don't want to see the columns with the start and end times, hide them or put them on another sheet.
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)
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/
I am trying to get a calculation of h:mm between two different times. I am using this formula
=TEXT(D21+E21, "h:mm")
When the Two cells are 12:00 and 12:30 or 12:00 and 1:00 it shows :30 and 1:00 respectively. When it is between 12:30 and 1:00, it shows 1:30. Note, all times are times of day.
Ultimately I want four cells, Time In, Time Out, Lunch In, and Lunch out, with a timespan showing time minus lunch. I am having trouble getting excel to give my anything close to accurate for nearly any input.
I recommend you don't use TEXT function. As the name implies - the result of TEXT function is a text value, which you might not be able to use in subsequent calculations. It should be sufficient to use just
=E21-D21
...then format result cell as [h]:mm
Change it to:
=TEXT(E21-D21, "h:mm")
(changed E2 to E21 to match the original question JMG)
Change it to TEXT(E21-D21, "h:mm") and also use 13:00 instead of 1:00, or add dates. It will fail if E21 is less than D21, and 1:00 is translated as 1AM. If you want to get the difference across days then add date information as well.