Specific date and time range in Excel - 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)

Related

Find Intersection between Times

Hello i'm learning Rust at the college and i'm in trouble with an exercise the professor gave us to learn use iterators better.
The exercise says that: you have 2 files, calendar1 and calendar 2 in this format:
Content of file calendar1:
08:00 20:00
10:00 11:30
14:00 16:00
where the first row is the start hour and the end hour of the workday.
The other rows are the scheduled appointments that are already done for that workday.
Given 2 calendars of the same day, and a number of minutes an appointment has to be taken, you have to write as std output all the possible intervals that are suitable for both the calendars.
Here is an example of output:
Content of file cal1:
08:00 20:00
10:00 11:30
14:00 16:00
Content of file cal2:
09:00 18:00
09:30 12:00
13:30 16:30
cargo run -- cal1 cal2 30
09:00 09:30
12:00 13:30
16:30 18:00
I've already put some codes and read the files properly and putted them in a struct using the NaiveTime Type to handle hours and minutes
#[derive(PartialEq,Clone,Debug)]
pub struct Calendar {
schedule: Vec<(NaiveTime, NaiveTime)>,
bounds: (NaiveTime,NaiveTime)
}
Now i'm in trouble because the exercise says that, in order to solve this problem, you have to use a complexity of O(M+N) where M and N are the length of the two schedule vectors.
Additionally to solve this the hint is: "use two indipendent iterator, for each list of appointments, and everytime you find a correct "hole" save the interval"
I really don't know how to use the iterators separately because i dont understand how can i check that an interval which, for example, is suitable for the first calendar, at the same time is suitable for the second one. Any help? Thank You

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

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.

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

count people scheduled at work

I have a table with shift start and end times, with #N/A if the person is not due in at all.
(Sample)
Mon Start Mon End
8:15 16:45
8:15 16:45
8:15 16:45
11:30 20:00
#N/A #N/A
8:15 16:45
8:45 17:15
9:30 18:00
13:30 22:00
I would like to know how many people are due to be on at a specified time
e.g. if i select 9:00 as the time, I would expect the result 5 from this query, and if I select 21:00, I would expect 1.
I have tried countif =COUNTIF(A2:A93,"<"&D2)-COUNTIF(B2:B93,">="&D2), but that just produces negative numbers for the start of the day, and positive for the end of the day.
with sumproduct, =SUMPRODUCT(--(A2:A93>=D2),--(B2:B93<D2)), I can only get 0 as the answer
Could someone point out where I am going wrong?
SUMPRODUCT won't ignore #N/A error values, if you have Excel 2007 or later try using COUNTIFS like this
=COUNTIFS(A2:A93,"<="&D2,B2:B93,">="&D2)

Resources