I am trying to calculate downtime for devices. I would like to count only those time which is laying in a particular time slot. I am calling this time slot Min & Max time. All the timestamp is with dates but when the date is changed time should calculate according to that. for one device I am able to do that but same formulas are not working for next device.
Logic: Timestamp is 22:00 and device the last timestamp was 6:00 hours before.
And Min 6:00 AM to 18:00 PM
So the downtime would be 2 hours. coz last time device communicated was 16:00 hours & downtime consider at 18:00 hours.
file
Break it down into steps. I will use Time(6,0,0) and Time(18,0,0) as your start/end times, but you may want to make them cell references. I will also use Min_Date and Max_Date as the 2 timestamps you are comparing
Step 0: Check if the day is the same - if so, just calculate as normal. Otherwise, carry on with the next Steps:
=MEDIAN(TIME(6,0,0), Mod(Max_Date,1), Time(18,0,0)) - MEDIAN(TIME(6,0,0), Mod(Min_Date,1), Time(18,0,0))
Step 1: How many Full Days downtime? (i.e. 2018-01-01 12:00 to 2018-01-03 12:00 has 1 full day, 2018-01-02) Multiply this by the hours per day:
=Max(Int(Max_Date)-Int(Min_Date)-1, 0) * (Time(18,0,0)-Time(6,0,0))
Step 2: How much of the First day was downtime?
=TIME(18,0,0)-MEDIAN(TIME(6,0,0), Mod(Min_Date,1), Time(18,0,0))
Step 3: How much of the Last day was downtime?
=MEDIAN(TIME(6,0,0), Mod(Max_Date,1), Time(18,0,0))-TIME(6,0,0)
Step 4: Add together Steps 1, 2, and 3
Just tie those together into 1 formula, and voilá.
Related
I try to store availability hours for different services. (Every work days (8, 9 hours), 24/7 etc.)
A work day can have different office times (08:00-16:00 or 09:00-17:00, 08:00-18:00 etc.)
There are also national holidays where a normal work day acts like a weekend, and any given weekend day can be also work day.
What is the best way to store this in a database (PostgreSQL)?
Background
The main goal is to calculate if how many minutes of a given time range is in service time.
A) A service time is only work days (08:00-16:00) and the date range is
[2019-10-21 15:00 (Monday) - 2019-10-22 09:00 (Tuesday)]. The whole range is 18 hours long, but only 2 hours were in service time.
B) I also want to calculate if I know the start time (2019-10-21 15:00) and there is 3 hours to finish the work (in work time) then when will be the end date? (2019-10-22 10:00 - 1 hour on Monday, 2 hours on Tuesday)
I would store the data exactly as how you described it.
You can have a table for work windows, i.e. Mon-Fri 08:00 to 16:00
And each service will have it's date ranges, start and stop. I'm guess a service will have multiple date ranges so you might need a date range table that has dateRangeId, start & stop columns.
When you want to calculate something, you pull data for the service and pull data for the work days and calculate what is the actual service time and any other questions you need answered :)
I'm trying to make an excel sheet where I only need to put in start and end time and excel chooses the correct pay rate and how many hours I've worked (already done) and outputs how much I've earned. So far I have a column (D) for the date of shift (DAY, day of month, Month, year) column for hours worked (E), column for start time and end time (F, G) I have already written the formula to calculate the hours worked but in Australia where I live my pay rate increases after 7 PM, and increases again after 12 AM. Is there a way to have excel automatically know that it needs to take the hours worked before 7 PM and multiply it by a 24.41, then the hours worked between 7 PM and 12 AM by 26.54 etc, if my shift starts for example at 5:30 pm and ends at 3 AM?
These are the different payrates at the different times: (Time is in cell A1, Pay rate is B1, etc)
Time Pay Rate
Regular $24.41
Mon-Fri 7pm-midnight $26.54
Mon-Fri 7midnight-7am $27.60
Saturday $29.30
Sunday $34.18
Public Holidays $48.83
Thanks in advance
Solutions to all of these type of questions use the standard formula for overlapping time periods
=max(0,min(end1,end2)-max(start1,start2))
The best way to do it IMO is to simplify it two ways
(1) By splitting any times that cross through midnight into two parts, one up to midnight and one from midnight onwards
(2) Using a lookup table to match the conditions (day of week and time of day) to the payscale.
Then use an array formula to do the lookup and calculation. Because you can't use MAX and MIN as above in an array formula, you have to write it out using if statements and the formula gets pretty long
=SUM((WEEKDAY(E2,2)>=PayRates!$A$2:$A$10)*(WEEKDAY(E2,2)<=PayRates!$B$2:$B$10)*24*PayRates!$E$2:$E$10*
IF(IF(G2<PayRates!$D$2:$D$10,G2,PayRates!$D$2:$D$10)-IF(F2>PayRates!$C$2:$C$10,F2,PayRates!$C$2:$C$10)<0,0,
IF(G2<PayRates!$D$2:$D$10,G2,PayRates!$D$2:$D$10)-IF(F2>PayRates!$C$2:$C$10,F2,PayRates!$C$2:$C$10)))
This has to be entered using CtrlShiftEnter
This is how my pay rates are arranged
NB When the finishing time of a pay rate is midnight, it is entered as 1 (you want it to be 24:00, but entering 24:00 just gives you the same as 00:00)
And this is the main sheet
With the following columns
A,B and C are your input.
Split
=B2<A2
StartDate1 and StartTime1 are just a copy of your input
EndTime1
=IF(Split,1,B2)
StartDate2
=E2+Split
StartTime2
00:00
EndTime2
=IF(Split,B2,0)
Total1
The main formula
Total2
The main formula copied across by four columns to give any pay for the second day when the shift goes through midnight.
Total
Total1+Total2
Public holidays can be added fairly easily.
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/
Checking out a formula that can take the difference of the time schedule. I have
=ABS(TRIM(LEFT(M2,8))-TRIM(RIGHT(M2,8)))*24
but it doesn't take into consideration the hours that will go beyond 12AM (the next day). Example on the second row (4:00 PM - 12:00 AM). I am only interested with the time that it elapsed from the start time to the end time, which is supposed to be 8, but the result is different because of the difference in the date. Any suggestions without adding a date column?
You need to add 1 to the time when it goes to the next day.
=IF(MID(M2,FIND("-",M2)+2,LEN(M2))<LEFT(M2,FIND("-",M2)-1),1,0)+MID(M2,FIND("-",M2)+2,LEN(M2))-LEFT(M2,FIND("-",M2)-1)