How do I format cells to display a time range instead of just the time? - excel

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.

Related

Count for every 'x' that falls into an interval within a given time range?

I'm looking to get a headcount of people available every hour within a time frame.
Employee
Start Time
End Time
Emp name
8:30 AM
10:30 AM
Emp name
8:30 AM
10:45 AM
Emp name
8:00 AM
10:15 AM
If I were to take a count of employees available at 9:45 AM, I should get 3. Or maybe I want 15 minute intervals and want to know my headcount at 8:15, which would be 1.
Currently my solution is to make a table for every hour in a day using the following formula to add a tally for every hour an employee is available:
=IF(AND($G9>=R$1,$G9<S$1),1,IF(AND(R$1>$G9,R$1<$H9),1,""))
And i get something that looks like this:
Start Time
End Time
8:00 AM
9:00 AM
10:00 AM
11:00 AM
8:30 AM
10:30 AM
1
1
Finally I can pivot this or countif it to get my total.
Is there a more elegant solution to this? Preferably one that allows me to change the interval but still gives me an accurate count. Even better if I don't need to build out the interval table.
I'm open to using VBA or formulas.
Overall, what is this problem called? I'd like to look up a pythonic solution on my own time for some self study.
If every line represents a different employee, then just use COUNTIFS:
=COUNTIFS(B:B,"<="&E2,C:C,">="&E2)

Excel formula to measure duration of breaks

I am working on a formula which will measure the duration of time my employees went on break.
The data I have:
NAME LOGIN LOGOUT TYPE DATE
JOHN 5:00 PM 6:00 PM BREAK 8/1/2018
MARK 6:15 PM 7:00 PM BREAK 8/1/2018
LUKE 5:05 PM 5:00 PM BREAK 8/1/2018
MARK 6:20 PM 9:00 PM LUNCH 8/1/2018
LUKE 6:20 PM 9:20 PM LUNCH 8/1/2018
JOHN 6:15 PM 9:00 PM LUNCH 8/1/2018
I want to measure the duration of their breaks. For instance, John logged out at 6:00 PM for his break and then logged in again at 6:15 PM. Unfortunately, the data I have are not in chronological order hence I need to lookup the specific values first depending on the date. Could you please provide me with a formula that will lookup John's logout time tagged "break" on 08/1/2018 and then subtract it from his login time on the same date to get the duration.
Use AGGREGATE to return the next login after the logout and subtract the current logout from that:
=IFERROR(AGGREGATE(15,6,($E$2:$E$7+$B$2:$B$7)/(($E$2:$E$7+$B$2:$B$7>E2+C2)*($A$2:$A$7=A2)),1)-(E2+C2),"No clock in")

Excel: auto format time of day when inputting time

I'm inputting time in and time out logs for my business to calculate the total hours worked by individual contractor companies visiting my site. We operate from 6:30am to 5pm. Excel automatically formats the data as AM, except for 12:00-12:59 which it correctly assumes is PM. I need excel to recognize that any time between 12:00 and 5:00 is PM. This will save me from having to type PM for each "time out" which over the course of a year will save me hours.
I'm not really sure how to do this. I'm guessing an if/then macro?
You can change the cell format as shown below:
when you type 17:00 is correctly displayed as 5:00 PM
I just use military time to get around this problem. 5 PM is not 5:00, but rather 17:00. Then you don't need to put in a PM or anything. Note: This is just for inputting the time. You can still display the time as 5:00 PM or whatever by formatting those cells or columns as the 'Time' type.
1 PM = 13:00
2 PM = 14:00
3 PM = 15:00
4 PM = 16:00
5 PM = 17:00
6 PM = 18:00
etc.

Calculating time range in Excel

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

Specific date and time range in Excel

I have twelve events every day from 8am to 8pm every hour.
I have two columns in Excel spreadsheet: "date and time" and "description".
I need to add date and time stams for each cell of "date and time" column in the format
16/11/2011 08:00
So the first twelve cells will look like that:
16/11/2011 08:00
16/11/2011 09:00
16/11/2011 10:00
16/11/2011 11:00
16/11/2011 12:00
16/11/2011 13:00
16/11/2011 14:00
16/11/2011 15:00
16/11/2011 16:00
16/11/2011 17:00
16/11/2011 18:00
16/11/2011 19:00
16/11/2011 20:00
Then the next day shall come:
17/11/2011 08:00
17/11/2011 09:00
17/11/2011 10:00
17/11/2011 11:00
17/11/2011 12:00
17/11/2011 13:00
17/11/2011 14:00
17/11/2011 15:00
17/11/2011 16:00
17/11/2011 17:00
17/11/2011 18:00
17/11/2011 19:00
17/11/2011 20:00
Is there a way I can get the column filled in automatically for several months?
Put your first date in cell A1:
16/11/2011 08:00
And in cells A2 and below, add the formula:
=A1+TIME(IF(HOUR(A1)=20,12,1),0,0)
and then drag down your formula till where you need.
[EDIT] Explaining a little bit the formula: in order to keep the formula quite simple, it is rather specific.
Meaningly,
the formula starts at the previous date A1 +
then, it adds some hours (with the TIME function) but no minutes nor seconds (0,0) i.e. see the end of the formula
to choose the number of hours to add, it checks wether the previous date hour is 8pm (i.e. HOUR(A1) = 20).
If so, it adds 12 hours so that the new date is at 8am the next morning.
If not, it adds only 1 hour (next event)
[EDIT 2] New formula to skip week-ends (it checks wether the previous date is a friday (WEEKDAY=6) and hour is 8pm (HOUR(A1)=20). If so, it adds two days (just add 2 because date in Excel are stored as serial number and unit is a day).
=A1+TIME(IF(HOUR(A1)=20,12,1),0,0) + IF(AND(HOUR(A1)=20,WEEKDAY(A1)=6),2,0)

Resources