Determine if time is before or after specific time - excel

I have an Excel sheet with two date-time columns: Start Date and End Date. I need to calculate overtime by determining how many hours and minutes were worked before 08:00 and after 16:30.
Examples:
COLUMN A COLUMN B
1 2017/01/04 16:00 2017/01/04 18:00
2 2017/01/05 18:00 2017/01/05 21:00
3 2017/01/08 08:00 2017/01/08 17:00
4 2017/01/09 07:00 2017/01/09 09:00
I know the calculation for duration between times (=TEXT(B1-A1,"h:mm")), but I'm struggling to determine if a date-time is before 08:00 or after 16:30.
I've played around with TIMEVALUE("8:00:00"), TIMEVALUE("8:00:00 AM") and TIME(8,00,00) in my calculation, but the it did not work,
e.g. =IF(A1<=TIMEVALUE("8:00:00 AM"),"Yes","No") returns "No" even for A4 (2017/01/09 07:00)
I'm struggling with the calculation and the logic on this one. So far i'm using,
=IF(MOD(F2,1)<8/24,8/24-MOD(F2,1),0)+IF(MOD(G2,1)>16.5/24,MO‌​D(G2,1)-16.5/24,0)

Try this:
=IF(TIMEVALUE(A1)<=TIMEVALUE("8:00:00 AM"),"Yes","No")

Stick with treating time as time; only treat time as text when you have bad data (time as text is bad data) and then only enough to get it to be time as time.
To get the number of hours and minutes before 08:00 AM,
=MAX(0, TIME(8, 0, 0)-TIMEVALUE(TEXT(A2, "hh:mm;0;#")))
To get the number of hours and minutes after 16:30 AM,
=MAX(0, TIMEVALUE(TEXT(B2, "hh:mm;0;#"))-TIME(16, 30, 0))
In the following image you can see that I have left one group as true time and the forced the following group to be time as text¹. Both return correct results.
¹ Unless specifically formatted otherwise, numbers and dates/times are right-aligned in a cell; text is left-aligned.

Related

Excel formula: how to sum total time between different time intervals based on a time condition

A B
Departure Date Arrival date
4/9/18 22:40 5/17/18 14:10
8/5/18 18:20 8/22/18 6:00
9/24/18 22:20 10/10/18 6:00
10/22/18 14:00 11/7/18 6:10
12/3/18 22:25 12/19/18 6:00
1/16/19 0:00 1/30/19 0:00
I need some help please. I have to calculate the total travel days for our employees for a specific period of time. I have columns A and B (all are date and time). Column A is the Departure Date, Column B is the Arrival Date.
Question: which is the Total number of travel days between:5/10/2018 and 12/10/2018?
Try this, you may need to edit it to match your needs though...
IF(AND(A4>=$A$1,B4<=$B$1),B4-A4,IF(AND(A4<=A$1,B4<=$B$1),B4-$A$1,IF(AND(A4>=A$1,B4>=$B$1),$B$1-A4)))
See:

Allocating staff to 30 minute intervals

I’m trying to create either a spreadsheet or macro that allows me to put and employee start and finish time in and then show me by each half hour how many half hours they are in.
For example;
Employee 1 - 08:30 to 10:15
The output I would want is;
08:00 0
08:30 1
09:00 1
09:30 1
10:00 0.5
10:30 0
11:00 0
So between 8:30 and 9:00 shows as one because that employee was in during that half hour. But between 10:00 and 10:30 it shows 0.5 because the employee was only in for half of that period
Then as I add more data it tells me which half hours they are covering.
I’ve tried using the ceiling and floor values, counta, countif, countifs, v and hlookups but just can’t get the desired effect.
I’m guessing it would need to be a macro.
Assuming C1 and D1 contain the start and end times of a shift and column A contains the times, use the following formula in column B:
=IF(A2>D$1,C2,IF(AND(A2>=C$1,A3<=D$1),1,MAX(0,A3-D$1)/(1/48)))
Limitations: shifts cannot cross over days, days cannot start before 00:00 or end after 23:59

Excel Time Comparison and Subtraction

I am trying to do a time subtraction in excel of 30 minutes and I am running into a speed bump. So the table I have are as follows.
Table "Schedule"
Column 1 is day of the week (Mon-Sun) (formated as general, as this is plain text)
Column 2 is start time of the shift (formated as h:mm AM/PM)
Column 3 is end time of the shift (formated as h:mm AM/PM)
Column 4 is duration of the shift (start to end) (formated by formula (TEXT(col3-col2,"h:mm")) )
Column 5 is paid hours (if the total hours is over 6.5 then subtract 0.5 hours for an unpaid lunch) (formula IF(col5>"6:30",col5-"0:30",D5) )
The issue is any time allotment over 10 hours start to end (where column 4, the duration hits 10 hours) no lunch is subtracted at all.
So...
Start 9:00 AM, End 6:59 PM, Hours Total 9:59, Hours Paid 9:29
But...
Start 9:00 AM, End 7:00 PM, Hours Total 10:00, Hours Paid 10:00
and that should obviously not happen. I can't find anything on google so I figured the excel gurus here may have some advice.
Thanks!
If your time columns are stores using excel's dedicated time format, this should be straightforward. Mixed data types are likely your problem.
First, be sure your time columns (columns 2 and 3) are set using the time function, i.e.,
=time(hours,minutes,seconds)
Then, you should be able to add and subtract easily.
Column 4: = column 3 - column 2
... then subtract 30 minutes also using the time() function:
Column 5: = if(column 4 > time(6,30,0),column 4 -time(0,30,0),column 4)
Excel stores time values from 0 to 1. So 24 hours=1, 12 hours=.5 etc. That means 6.5 hours=0.270833333 and .5 hours=0.020833333. As a result you can just do a simple if statement.
=IF(D2>0.270833333,D2-0.020833333,D2)
To turn it into a time format, is to just use excel's time formating options.

Finding earliest date in excel

In one column I have to 10 times and dates (I have merged date and time in a cell). How do I find top 5 earliest dates and times? I can’t use function MIN() because I have date and time together. How should I write the function?
You need to first format your data in date/time format in Excel.
Example, the following data is entered
16/7/2018 15:00
18/7/2018 12:05
25/8/2018 11:00
13/7/2018 09:00
15/7/2018 14:00
15/7/2018 11:00
You can use the formula =small(range, rank) to find the smallest n figure. For instance, =SMALL($A$1:$A$6,1) would give the smallest (earliest) date, 13/7/2018 09:00 in this case. =SMALL($A$1:$A$6, 2) would give the second smallest (earliest) date, 15/7/2018 11:00 in this case.

Excel - Date Range includes given time of day (a better approach)

Given a set of DateTime ranges in excel, such as:
Start Finish
13/03/2012 10:00:00 14/03/2012 03:00:00
15/03/2012 08:30:00 15/03/2012 10:00:00
And some TimeSpan such as:
Start Finish
07:00:00 09:00:00
How would you determine if the time span falls in some given date range?
An approach like this might be a start:
AND(B2 < DATEVALUE(TEXT(B2, "dd/mm/yyyy")) + TIMEVALUE("07:00:00"),
B3 >= DATEVALUE(TEXT(B3, "dd/mm/yyyy")) + TIMEVALUE("09:00:00"))
Though it relies on the being able to provide the start/finish values explicitly as opposed to two dates in any order. A conditional on start <= finish would do, but seems like it's overly complicated.
Is there a better way?
Edit: Bonus points for a simple approach to finding the percentage of the date range that falls in the time span
Seems like you're assuming that the dates will always be the same day, is that the case?
Try
=AND(MOD(A2,1)<=F2,MOD(B2,1)>=G2)
For percentage
=MAX(0,MIN(MOD(B2,1),G2)-MAX(MOD(A2,1),F2))/(B2-A2)
Update:
If the date range can be unlimited, 1 day or many, then you can use this formula to get the total hours within the timespan
=(INT(B2)-INT(A2))*(G$2-F$2)+MEDIAN(F$2,G$2,MOD(B2,1))-MEDIAN(MOD(A2,1),G$2,F$2)
that assumes that the timespan doesn't cross midnight - if timespan may cross midnight, e.g. could be 08:00 - 11:00 but could also be 22:00 - 03:00 then this formula should work
=(F$2>G$2)*(B2-A2)+SIGN(G$2-F$2)*((INT(B2)-INT(A2))*ABS(G$2-F$2)+MEDIAN(F$2,G$2,MOD(B2,1))-MEDIAN(MOD(A2,1),G$2,F$2))
This should give the number of hours falling in the time span (but it's definitely not simple!):
=MEDIAN(F2,G2+(G2<F2),MOD(B2,1)+(MOD(B2,1)<MOD(A2,1)))
-MEDIAN(F2,G2+(G2<F2),MOD(A2,1))
+(F2<G2)*(MOD(B2,1)<MOD(A2,1))*MAX(MIN(MOD(B2,1),G2)-F2,0)
If this is greater than 0, the date range falls in the time span, divide this by B2-A2 for the percentage.
e.g. Date Range: 6:00PM - 9:00AM, Time span: 7:00AM - 7:00PM returns 03:00 which is 20% of the date range.
Say the date ranges are in columns A and B, and the Timespan in F2 and G2.
Apply the following formulas and drag down.
H2 = IF(AND($F$2>=RIGHT(A2,8),$F$2<RIGHT(B2,8),$G$2>RIGHT(A2,8),$G$2<=RIGHT(B2,8)),1,0)
Column H gives tells you if it's true for a particular date range.
I1 = SUM(H2:H4)/COUNT(H2:H4)
I1 gives you the percentage

Resources