Check range of times in excel to ensure they are within core hours - excel

I am trying to check to see if the following Times in the picture fall within a certain core hour of 0930 - 1430, in military time. This breaks because you aren't clocked in at 930 therefore missed a half an hour of core time.
Currently I am using min/max to check for those columns which works until this example. Any ideas would be great!
Here is an example:
Here is what the output should look like (even though the math is wrong.
It should say CR Missed=1.5 (Core Hour starts at 930 and clock in was 11).
The current code I am using
=IF(AND(COUNTA(J8:J12)<>0,COUNTA(K8:K12)<>0),IF(AND($AQ$15>=MIN(J8:J12),$AR$15<=MAX(K8:K12)),"","CR Missed = "),"")
Edit: Sums are not relevant (it just adds the times) AQ=0930 and AR=1430 (The range of "Core Hours")
Essentially you can enter in different times in each row and I am trying to make sure that you are 'logged in' between required times of 0930 and 1430. Currently the Min/Max equation works ish but doesnt cover the shown example where I am actually missing 30 mins (logged out at 0900 and logged back in at 1000).
I feel like I am missing some logic or command. Sorry, I hope this helps.
From Comments and to add clarity, added an example of the ouput
There can be more lines; I have up to 5 (Just hidden)
The times dont have to be in order but generally thats how they would be entered.
No these are technically different time codes (Leave/Sick/Regular) You would not overlap Sick and Leave for example
Solved
I would like to thank everyone for the help!
The function I ended up using was Ron's example with a twist. As his example showed how many hours worked that were within a time range; I wanted to show how many were missing; and since multiple check ins/outs could happen I just covered all the available slots.
=ABS((5-(MAX(MIN(EndTime,K9)-MAX(StartTime,J9),0)*24))-(5-(MAX(MIN(EndTime,K10)-MAX(StartTime,J10),0)*24)))
So this will give me the number of missed hours between required time interval with multiple check in and check outs.

Preface
My approach was to look for the first time-slot that covered the starting time (9:30).
If we find a time-slot like (7:00 - 10:00), we need to check if the next time slot starts at 10:00.
If the next time slot covers 10:00, we will check this time slot's end time with the next one.
And we repeat this process until all time-slots have been checked. If the time we end up with is greater than your "core end time" (14:30), then we know that all hours of the core hours have been covered continuously without breaks (might even be more).
On the contrary, if it is smaller, the value we ended up with, is the last point in time that they worked continuously without any gaps.
Formulas & Explanations
Insert start time into D1, and end time in E1.
In C2 and downwards is: =IF(AND($B2>$D1;$D1>=A2);$B2;$D1)
This is what checks if the time we were looking for was in this interval, if it was, this value will change into the end time of the time slot. If not, it will remain as the previous - this is what lets us know not all core hours have been covered.
D2 and downwards is simply: =MAX(D1;C2) (This could be included in C1, but for readability and to easier understand, I made it a separate column.
Finally E4, whether or not all core hours have been covered is: =C4>=E1, which becomes TRUE or FALSE. If you want the "CR Missed", that will be a simple: =IF(E4;"";"CR Missed")
I realize this isn't very dynamic, so if you have more time slots, you will have to copy the formula down further.
So, maybe this won't be the ultimate solution, but rather do the job and perhaps be enough for you to expand upon.
Best regards! ^_^

It is not clear to me what you want for output. Perhaps this will get you started.
To compute the hours from Start=> End that fall within a certain range (eg: Core Time):
=MAX(MIN(TIME(14,30,0),End)-MAX(TIME(9,30,0),Start),0)
So you could do something like:

Related

Caclulate if Now() is between 2 times across midnight Excel

I feel a bit noob asking this but been scratching my head trying to figure out a solution for this problem. (ADHD hitting hard as well)
I have a list of people that are schedule to work in various time segments, some of them with shifts that crosses midnight, and after comparing it with a different data set know if the person if the person is working or not.
Column A contains the list of people,
Column B and C contains the days off, combined with + =Today()
Column D contains the time when the shift begins, (As it time only, added =Today)
Column E contains the time when the shift ends,
Column F will indicate if that specific person is in their day off or they need to work, used the following code for it
=IF(OR(B3=(TEXT(TODAY(),"ddd")),C3=(TEXT(TODAY(),"ddd"))),"Week-Off","Workday")
In column G I want to know if the person is working or they are absent after matching it with another table using this formula
=IF(F2="Workday",IF(AND(Now()>=$E2,(Now()<=$F2),"Scheduled","Off-Shift")," ")
So far the code has worked for everyone who has schedules that ends at 11:59 pm, but when the shift ends at midnight or it crosses midnight it provides incorrect results (Shows Offshift instead of Scheduled)
In Short I want to know if =Now() is between 2 times, when is in the same day or the shift crosses midnight.
Code (Asume Now() is 1:30 am)
=IF(F4="Workday",IF(AND(Now()>=$D4,(Now()<=$E4),"Scheduled","Off-Shift")," ")
Expected Result
Schedule
Actual Result
Off-Shift
As on now i feel is a pretty easy solution but unable to wrap around a solution, and somehow my brain is focus on using IF. As an extra bonus if it can be done by Excel-VBA it will be a plus
After looking a bit further found the solution in the following post: Determine if a given time is between start and end time

Find earliest entry in a table

Consider the following table of employees.
It's fairly simple right? Clock in when you start, clock out for lunch, clock back in after lunch, clock out when you leave. But can someone please tell me what time these employees actually started? So for example how would you go about saying Tom was here at 6:51 AM and not at 12:23 PM?
For more reference, all entries look like this. They have at least 4 entries, (some one, no lunch).
How do I go about writing a formula that returns the start time?
I edited the table and added a helper column for the date. See below.
ANSWER:
=AGGREGATE(15,6, $C$2:$C$7/((A11=$A$2:$A$7)*(B11=$B$2:$B$7)),1)
If the working hours are within the day, you can search for the smallest time. If there is a night shift over midnight, then there is a problem ...
=AGGREGATE(15,6,(1/($A$2:$A$5=A2)*(INT(B2)=INT($B$2:$B$5)))*($B$2:$B$5),1)
I've written down this formula for range E2:
=IF(AND(A2=A3,TRUNC(B2,0)-TRUNC(B3,0)=0),MIN(B2,B3),IF(AND(IFERROR(TRUNC(B2)-TRUNC(B1)=0,FALSE),E1=MIN(B2,B1)),"",B2))"
Since english is not my default language on Excel, i've just manually translated it. Anyway, just in case, here is the VBA code to paste it in range E2:
Range("E2").FormulaR1C1 = "=IF(AND(RC[-4]=R[1]C[-4],TRUNC(RC[-3],0)-TRUNC(R[1]C[-3],0)=0),MIN(RC[-3],R[1]C[-3]),IF(AND(IFERROR(TRUNC(RC[-3])-TRUNC(R[-1]C[-3])=0,FALSE),R[-1]C=MIN(RC[-3],R[-1]C[-3])),"""",RC[-3]))"
I've tried various configurations and it works for me. Only point: list must be sorted by Name and Clock In.

Calculate minutes in specific period

I have a spreadsheet which has employee working times, listed as Sat-In and Sat-Out for a specific date. The employee shift spans several ours and each "In-Out" period is recorded as a separate line which means the time between the Sat-Out and the next Sat-In means the employee is on a break. I also calculate the time, in minutes of each "sitting" period.
What I can't seem to figure out is how to add a formula which takes the data and further refines it in this manner:
1. I have a core period of 1030-1530, as an example, which is the busy time and requires the maximum employee coverage. The shifts of employees generally spans this core, but in some cases their shift may start or end in the core.
2. I want to calculate how many minutes the employee worked within the core only. I can obviously do this manually using the data, but a formula would be preferred, if possible.
3. As an example, if a person sat-in at 1445 and sat-out at 1545, the core time calculation would be 45 minutes (1445-1530).
I've attached a snapshot of the data to help my explanation.
FYI - the information is pulled from a database as JSON data and converted to excel. I'm not very familiar with JavaScript, but if someone knows a way to do it programatically, I'm willing to give it a try and learn.
Thanks!
![excel]: https://photos.app.goo.gl/dRSTE72CXNa18RzP8
In below example I've used: =MAX(0,MIN($O$2,H2)-MAX($O$1,G2)), and formatted like [mm].
In Excel, units are days, so if you want to calculate the amount of minutes between two timestamps, you need to subtract both and multiply the differencee by 24*60 (being the amount of minutes in one day).
E.g. You start working at 09:07 (cell B2), and finish at 18:07 (cell B3), having a 45-minutes break. Then the time you worked in minutes, is:
=(B3-B2)*24*60-45
Make sure the cell formatting is correct (general), you'll get : 495.

Number of minutes in a time range - EXCEL

I have a sheet for tracking my hours at work. We also have a time period between the hours of 07:30 & 18:00 where we can accrue 'flex time'. I want to know from my in and out times, how many hours:minutes I have made in flex.
Please can someone help with the calculation?
The standard way of doing these is to use the overlap formula for two intervals
=max(0,min(end1,end2)-max(start1,start2))
So in your case it would be
=MAX(0,MIN(C2,TIMEVALUE("18:00"))-MAX(B2,TIMEVALUE("7:30")))
If some of your time cells contain strings instead of numbers you would need to check for these. One way of doing it is
=IFERROR(MAX(0,MIN(C2+0,TIMEVALUE("18:00"))-MAX(B2+0,TIMEVALUE("7:30"))),0)
If you ever did a night shift including midnight the formula would need further modification.
Fixed my formula to get correct answers. Bit odd but works now!
=C4+IF(A4-TIME(7,30,0)<0,A4-TIME(7,30,0),0)-IF(B4-TIME(18,0,0)>0,B4-TIME(18,0,0),0)
We take the total time then
if our time starts earlier than flex time starts, we ADD the difference between our start time and flex time, which of course will be a negative number
if our end time ends later than flex time ends, we SUBTRACT the difference between our end time and flex time

Repair incorrectly formatted time 'hh:nn:ss' when h=0

I'm doing a report which calculates people's time to determine their pay. We pull reports from our servers and paste them into Excel to do the calculations. I have run into an issue when pulling the data: if the time they logged in for was less than an hour our formula is not working:
=IF(E159="","",((HOUR(E159)+(MINUTE(E159)+(SECOND(E159)/60))/60)))
This gives an error (#value) if the time is :34:15, but if it's 00:34:15 then it's fine.
Formatting the cell does not appear to work.
I'd like to go through this column and add the 00 to all values missing it, and I need some help or guidance from there.
Another question on SO looks like it may help, but I'm unsure on how to use it.
Assuming that The tiem is in cell E159 from your above formula, you can append a 0 to the start of the time. This will fix all the times that have the hour missing and won't affect the other lines.
="0"&E159
You can then replace all of the E159 references in your original formula with this edit so that it looks like this:
=IF(E159="","",((HOUR("0"&E159)+(MINUTE("0"&E159)+(SECOND("0"&E159)/60))/60)))
While it's hard to read, it does the trick.
While that answers you question.. I think that there is a better way to achieve this formula.
It looks like the end result you're looking for is the time converted to hours, with mulutes and seconds as a decimel to the next hour. You can achieve this by doing:
=E159*24
Which will give you the same result as your original formula.
And then to combine that with my first answer to get a formula that looks like:
=("0" & E159)*24
This approach is much easier to read / edit and provides the same output.
Why This Works
Excel stores all dates as whole numbers, and all times as a decimel % to a day.
So when Excel is stores 12 hours it saves it as .5 because it is half of a day.
By dividing the time output by 24 we are converting the entire time value down from a % of day to a % of hours.

Resources