How can I (easily) format long intervals (over 30 days, but including time components) - excel

I am using a spreadsheet to record the intervals between certain medical events. Each event's timestamp is recorded in one column, so the interval between each event is the difference between consecutive cells (and the time since the last event uses now()).
First problem: I want to display the interval in days, hours and minutes. None of the built-in formats will do this, they report the days remaining after discarding complete months. So I am using this expression:
TEXT(TRUNC(C2-C1),"0") & " days " & TEXT(MOD(C2-C1,1),"hh "" hrs "" mm ""mins""")
which (e.g.) shows "46 days 13 hrs 44 mins". I was hoping there was a way to format a date/time value to show this rather than making the cell a string value, but I haven't been able to find one.
Second problem: I want to display the average value of all completed intervals in the same format. Because I can't average the string values produced by the previous expression I need to average the numeric equivalent (which I'd prefer not to have visible in the sheet) and then convert it to a string as for a single interval.
I can probably do this with a similar approach (if I don't run out of characters to enter the formula) but it seems to me that there must be a better way.
Ideally there is a solution which will work in Excel 2010. Has anyone solved a similar problem before and can give me some pointers?
Thanks, T
Edit: Some data to show what I am working with (I hope the image is readable). Here's a few lines from the sheet.
The formula for H2 etc. is
=IF(G2="c",NOW()-C2,"")
I5 is calculated as the difference between C5 and Cprev (where prev is chosen so that D5 and Dprev are both set). Obvious extension of this for J and K.
M2, M3 and M4 are respectively
=AVERAGEIF(K5:(INDIRECT("K"&(ROWS(K:K)))),"<>0")
=AVERAGEIF(J5:(INDIRECT("J"&(ROWS(J:J)))),"<>0")
=AVERAGEIF(I5:(INDIRECT("I"&(ROWS(I:I)))),"<>0")
Now, I can use a custom format for the values in H, I and J, and for M3 and M4, because these values will never exceed a few days. But values in K and M2 will be somewhere around 100 so I can't just format the raw value.
With custom formatting applied:
Here K6 and M2 say "27 days.." not "87 days..". That's what I'd like to fix nicely, hopefully without populating additional cells or writing a 3gl function to do it.

Date_Times in Excel are stored as days (with the decimal part representing parts of a day).
If the date matters, rather than just a number of days, then day zero is 1899/12/31.
Your first thought was right - do with formatting, not by turning a number into a string.
Entering date into A and time into B, with C=A+B is a good start, so that you can E.g. subtract one point in time from another without having to do anything about straddling midnight, month-ends etc, calculate averages etc.
Consolidating the comments already here: per https://support.microsoft.com/en-us/office/format-numbers-as-dates-or-times-418bd3fe-0577-47c8-8caa-b4d30c528309 you cannot get d for days above 31 (and it won't accept a format 0 hh:mm:ss )
I suggest that you do all your calculations using just numbers to get to say column M, and in N2 put =M2 etc, so you have the same values twice.
Then for formatting, use Format Cells | Number | Custom.
In column M put 0 "days".
In column N put hh "hours" mm "minutes".

Related

Excel: Count Total Schedules at 30 Minute intervals taking day into account

In assessing how many agents can be added to certain times of day without exceeding the number of seats in the call center, I'm trying to discern how many agents are scheduled for each half hour interval on each day of the week.
Using the =SUMPRODUCT(((A$2:A$1000<=D2)+(B$2:B$1000>D2)+(A$2:A$1000>B$2:B$1000)=2)+0) formula I've been able to identify how many total agents work for each interval, however this doesn't take the day of week into account.
I currently have my spreadsheet setup this way:
K is the start time of the shift, L is the end time of the shift, M to S pulls data from another sheet that shows a 1 if the agent works on that day of the week and 0 if they do not, and then U has all the time intervals listed out. In the example, it's cut off but the columns continue down as needed. U goes to 49 and I've just been using a range from 2 to 500 for the others as we currently do not have that many shifts and I'm leaving space for the moment.
After some Googling, I tried =SUMPRODUCT(--(M2:M500="1"),(((K$2:K$1000<=U2)+(L$2:L$1000>U2)+(K$2:K$1000>L$2:L$1000)=2)+0)) but it only returns #VALUE! so I'm not sure what I'm doing wrong.
Any suggestions of how I can make this work? Please let me know if more information would be useful. Thanks.
=sumproduct(($K$2:$K$1000<=U2)*($L$2:$L$1000>=U2))
That will count the number of occurrences where the start time is less than or equal to the time in U2 AND the end time is greater than or equal to U2. It will check time from row 2 to row 1000. Any time one condition is checked and its true the comparison will result in value of TRUE and FALSE when its not true. The * act like an AND condition while at the same time converts TRUE and FALSE values to 1 and 0. So both conditions have to be true for a value of 1 to result. Sumproduct then totals up all the 1 and 0 to get you a count.
In order to consider the days of the week, you will need one thing to be true. Your headers in M1:S1 will need to be unique (which I believe they are). You will need to either repeat them in adjacent columns to M or in say V1 you have a cell that can change to the header of the day of the week you are interested in. I would assume the former so you can see each day at the same time.
In order to do this you want to add more conditions and pay attention to you reference locks $.
In V2 you could use the following formula and copy down and to the right as needed:
=sumproduct(($K$2:$K$1000<=$U2)*($L$2:$L$1000>=$U2)*(M$2:M$1000))
UPDATE #1
ISSUE 1 Time ranges ending the following day (after midnight)
It is based on the assumption that the ending time is later than the start time. When a shift starts at 22:00 and end at 6:30 as an example, our mind says that the 0630 is later than 22:00 because it is the following day. Excel however has no clue that 0630 is the following day and without extra information assumes it to be the same day. In excel date is stored as an integer and time is stored as a decimal. When you only supply the time during entry it uses 0 for the date.
In excel the date is the number of days since 1900/01/00. So one way to deal with your time out is to add a day to it. This way excel will know your out time is after your in time when the hour is actually earlier in the day.
See your sample data below.
Using your sample data, I did a straight copy of the value in L and placed it in M (=L3 and copy down). I then changed the cell display format from time to general. This allows you to see how excel sees the time. Note how all the time is less than 1.
In column N I added 1 to the value when the out time was less than the in time to indicate that it was the following day and we had not actually invented time travel. I also used the trick of a math operation will convert a TRUE/FALSE result to 1 or 0 to shorten the equation. I used =M3+(L3<K3) and copied down. You will notice in the green bands that the values are now greater than 1.
In the next column I just copied the values from N over using =N3 copied down, and then I applied just a time display format for the cell. Because it is only time format, the date is ignored and visually your time in column O looks the same as column L. The big difference is excel now knows that it is the following day.
you can quickly fix your out times by using the following formula in a blank column and then copying the results and pasting them back over the source column using paste special values.
=M2+(L2<K2)
The next part is for your time check. When looking at the 12:00 time you need to look at 1200 of the current day incase a shift started at 12:00 and you need to look at the 1200 period of the following day. In order to do that we need to modify the the original formula as follows:
=sumproduct(($K$2:$K$1000<=$U2)*($L$2:$L$1000>=$U2)*(M$2:M$1000)+($K$2:$K$1000<=$U2+1)*($L$2:$L$1000>=$U2+1)*(M$2:M$1000))
Note that the + in the middle of (M$2:M$1000) + ($K$2:$K$1000<=$U2+1)? This + acts like an OR function.
Issue 2 Time In/Out 15 minute increments, range 30 minute increments
You may be able to achieve this with the ROUNDDOWN Function or MROUND. I would combine this with the TIME function. Basically you want to have any quarter hour start time be treated as 15 minutes sooner.
=ROUNDDOWN(E3/TIME(0,30,0),0)*TIME(0,30,0)
Where E3 is your time to be converted
So your formula may wind up looking something like:
=sumproduct((ROUNDDOWN($K$2:$K$1000/TIME(0,30,0),0)*TIME(0,30,0)<=$U2)*($L$2:$L$1000>=$U2)*(M$2:M$1000)+((ROUNDDOWN($K$2:$K$1000/TIME(0,30,0),0)*TIME(0,30,0)<=$U2+1)*($L$2:$L$1000>=$U2+1)*(M$2:M$1000))
similar option could be used for the leaving time and rounding it up to the next 30 minute interval. In which case just use the ROUNDUP function. Though I am not sure it is required.

Controlling Excel time format input/output

Background: I have been officiating our local jogging events for about ten years now. I am responsible for handling the data of the participants (name, sporting club, bib number) split into their categories (age bracket+gender, distance). The main task is collecting their times, and processing that data (sorting the runners within their category etc). I can handle this with Excel mostly fine.
Problem: What is the ideal time format for entering the race times of the participants? The times are either in the format mm:ss or (for slower runners and/or longer distances) h:mm:ss. Excel doesn't seem to have a built-in format where the hours field is optional. For optimizing my workflow ideally I would like to have a cell format such that the input
47:12 is to be interpreted as 47 minutes and 12 seconds, and the input 1:09:38 is to be interpreted as 1hr 9 minutes and 38 seconds. However, Excel, with the best fitting cell format that I found, will insist that the input 47:12 means 47 hours and 12 minutes. For times exceeding 1 hour I would input 1:03:00 if I meant that the seconds field is to be left with value zero.
How to make Excel realize that when the format can handle up to three numbers as inputs, it would, when given only two numbers, move them towards the end?
Thinking: I "can" key in 47 minutes and 12 seconds as 0:47:12 all right. But because most of the times are under 1 hour, that is partly wasted effort. Also, using such a format the data is displayed on the screen together with that superfluous 0:. What's worse (IIRC) those leading zeros
also appear in the printed versions, which is strange (insulting even) in a shorter distance for junior participants.
My hack: I enter the times as general numbers in the mm,ss format (in these parts a comma serves as a decimal separator). Excel can sort those as numbers just fine. I then duplicate the data of that sorted column to another "printable" version (formatted as text), where the data is just copied, but I correct the times exceeding 60 minutes by hand. This works just fine as long as I'm not in a hurry (our event is not exactly Boston Marathon, say, less than 200 participants), and remember to hide the column that is not supposed to be printed. This is kludgy, and there have been accidents, when other officials have been rushing me to get the results printed.
I managed to create a format where the hour-field is optional. It works with a conditional format. First you format your cells as standard, so you get the times as comma-values. After that you create a conditional format for these cells, which has two rules:
if cellvalue > 0.04166667 format hh:mm:ss
if cellvalue < 0.04166666 format mm:ss
Result:
47:12
01:09:38
01:00:00
So you get what you really want and you can use the original values for sorting and so on.
EDIT:
For the input you need four additional columns. You enter the times as you want, e.g. 47:12 and 1:09:38. In the next three columns you split these values in hour, minute and second, whereby the interpretation limit is 3 hours (03:00), which is 0.125.
So, these are the formulas for the split columns (your input is in B1):
Hours: =IF(B1>0.125,0,HOUR(B1))
Minutes: =IF(B1>0.125,INT(B1)*24+HOUR(B1),MINUTE(B1))
Seconds: =IF(B1>0.125,MINUTE(B1),SECOND(B1))
And finally, you put all values togehter in the forth column:
=TIME(C1,D1,E1)
and use the conditional format above.
If you will be entering your data as
`mmm,ss`
where the comma is the decimal point, then you can convert it to "Excel Time" with the simple formula:
=DOLLARDE(A1,60)/1440
Format the result as you wish.
If you want everything displayed as h:mm:ss then use that as your custom format (Format > Cells > Number > Custom Type:...)
If you want h to be displayed only with values of 60 minutes or greater, then use
[<0.0416666666666667]mm:ss;h:mm:ss
for your cell's custom format.
Beware that seconds must be entered with two digits always. In other words
6,2 will translate to 6 min 20 sec.
6,02 will translate to 6 min 2 sec
I really like IQV's answer above, but as pointed out in the comment section, the leading zero will be required for the data entry side. If for whatever reason this is not acceptable you can use the following ugly formula to convert your time entered in your usual method of mm,ss to hh:mm:ss with the hh: being displayed as required. Unfortunately it converts the whole thing to text which means you can no longer perform math operations on it.
=IF(FIND(".",MOD(D2,60)&".")=2,"0","")&MOD(D2,60)
and since you use , as your decimal separator the formula would become:
IF(FIND(",",MOD(D2,60)&",")=2,"0","")&MOD(D2,60)
If you use ; as your list separator then your formula becomes
IF(FIND(",";MOD(D2;60)&",")=2;"0";"")&MOD(D2;60)
There are probably some cleaner formulas, but that will get you started. Just replace D2 with the location where your time is stored.
Again I still prefer IQV's answer as you can do much more with the time information when its stored as a number and not text.
Option 2
lets say you change your data storage method to hhmm,ss in cell D6. you could rip apart the information and reassemble it in a display friendly version as follows.
=IF(FIND(".",D6)<=3,LEFT(D6,2)&":"&RIGHT(D6,LEN(D6)-FIND(".",D6)),LEFT(D6,FIND(".",D6)-3)&":"&MID(D6,FIND(".",D6)-2,2)&":"&RIGHT(D6,LEN(D6)-FIND(".",D6)))
you will need to substitute your list separator for the , and then substitute a coma for the decimal.

MS-EXCEL: time averages + numbers to time

I am working on a project for my work and I am having an issue trying to take times and averaging them out. I am getting a #DIV/0! When I convert the cells to XX:XX.
Below are screen shots of the same data and function. The top is with regular numbers the bottom is where I formatted all cells to display in time XX:XX.
Numbers (works fine)
= AVERAGE(H29,J29,P29,V29,AE29,AJ29)
Time (XX:XX) however I get the #DIV/0!. The AVERAGE Function I am using looks like this:
=AVERAGE(H29,J29,P29,V29,AE29,AJ29)
Also, if possible, could I enter the data in regular numbers (not time) then have it display in average time (hours:min) on the right?.
Thank you.
When working in Excel with dates and times always leave the value as a number and apply formatting. where you have tried to enter a time in hh:mm, you need to show the hours even if they are blank, or the value of that cell becomes a string. But you can't average a string.
These are valid entries 00:23 or 0:23
:23 is not valid time, so is treated as a string
Valid times are stored as a number where 24 hours = 1.
Times are stored as a fraction for example 0:45 = 0.031250000
To fix it, add in the missing leading zeros, or if you have explicitly entered text strings: type a 1 in any cell and copy it, then select all of your time cells and do paste special multiply. That will convert them back to numbers and your average should work. Then apply your custom formatting of required .
I would suggest that users enter the time in minutes eg 17, 23, 92 and you average these, but for the conversion I suggest that you use a formula like this:
=AVERAGE(H29,J29,P29,V29,AE29,AJ29)/(24*60)
This will convert the average time in minutes, into a fraction of a day.
You can then put custom formatting onto the cell to change the format to hh:mm

COUNTIFS events between dates but also time

For reporting I export raw data from a pbx in CSV. There are many columns with data. Relevant for this case is:
Column A: Date of the events (there are many events on a same day)
Column B: Length of the events in seconds
Column C: Date + Timestamp of every event
I filter out all events shorter or equal to 90 seconds,
I am able to adjust the range by changing dates in 2 cells I created for this occasion (start date is in D1 & end date is in cell D2). Without integarting time I use:
=COUNTIFS(B:B;">=90";A:A;">="&D1;A:A;"=<"&D2)
It works like a charm. I select a range in cells D1 & D2 and I automatically get all the events between these dates excluding events shorter or = to 90 sec.
On top of this I need to know how many events / occurrences happen between certain timestamps. For example from November 1st till November 7th I need to know how man events happened between 12:00h and 13:00h, how many happened between 15:00h & 18:00h etc.
Logically I thought that just adding another criteria_range and criteria (in this example column C) would do the trick. Alas adding column C does not seem to work and I have spinned it many ways.
My intuition is that the DATE + TIME format is inadequate, innapropriate for my case.
Column C looks like this: 02/11/2015 21:59:47
Being european, I'm happy with the DD/MM/YYY notation, but it seems that no formula can take account of the TIME and neglect the DATE in front. Remember I already use column A for the dates. Here in column C I am interested in the TIMESTAMP.
Any aideas or suggestions are welcome.
Thank you very much in advance.
PS: I can always split the time from the date using text to column feature. Yet It means I will be formatting the raw exports and I would like to avoid that at all costs so that I can just copy paste new exports in my control sheet without having to do all sorts of formatting.
Without sample data it is difficult to tell whether you are treating the elapsed time as 90 seconds (integer) or 00:01:30 (as true seconds, a decimal portion of 1). Your formula seems to indicate the elapsed time as an integer but it is also wrong in other places (e.g. =< instead of <=) so the only thing for certain is that it is not a working formula. The same goes for determining the time window. Are you comparing it to 12 and 13 as integers or 12:00:00 and 13:00:00 as true time? They are decidedly NOT the same thing.
The SUMPRODUCT function can provide the cyclic processing required to treat a datetime as time only (e.g. MOD(C2:C12, 1)) or as an integer representing the hour of the day (e.g. HOUR(C$2:C$12)).
  
The formulas in F2, F5 and F7 are,
=COUNTIFS(B:B; ">="&E2; A:A; ">="&E3; A:A; "<="&E4)
=SUMPRODUCT((A$2:A$12>=E$3)*(A$2:A$12<=E$4)*(MOD(C$2:C$12; 1)>=E5)*(MOD(C$2:C$12; 1)<=E6)*(B$2:B$12>=E$2))
=SUMPRODUCT((A$2:A$12>=E$3)*(A$2:A$12<=E$4)*(MOD(C$2:C$12; 1)>=E7)*(MOD(C$2:C$12; 1)<=E8)*(B$2:B$12>=E$2))
If E5 and E6 were 12 and 13 instead of 12:00:00 and 13:00:00 then the formula in F5 would be,
=SUMPRODUCT((A$2:A$12>=E$3)*(A$2:A$12<=E$4)*(HOUR(C$2:C$12)>=E5)*(HOUR(C$2:C$12)<=E6)*(B$2:B$12>=E$2))

Excel 2007: How to display mm:ss format not as a DateTime (e.g. 73:07)?

I need to create and Excel table that computes daily training times. each row has the following fields: Date, Distance, Time and Minutes/Km. My main problem is that I want to display the Time in format of mm:ss. For example: 24 min and 3 sec should be 24:03, but "Excel" turns it to 00:03:00 (3 min after midnight). I've tried setting up "special formatting" but still "Excel insists" on formatting the hours. More over, training may exceed 60 minutes and I still want it only as mm:ss
My second question is after I'm done with the formatting issue, what is the simple way to compute Time/Distance?
enter the values as 0:mm:ss and format as [m]:ss
as this is now in the mins & seconds, simple arithmetic will allow you to calculate your statistics
Excel shows 24:03 as 3 minutes when you format it as time, because 24:03 is the same as 12:03 AM (in military time).
Use General Format to Add Times
Instead of trying to format as Time, use the General Format and the following formula:
=number of minutes + (number of seconds / 60)
Ex: for 24 minutes and 3 seconds:
=24+3/60
This will give you a value of 24.05.
Do this for each time period. Let's say you enter this formula in cells A1 and A2. Then, to get the total sum of elapsed time, use this formula in cell A3:
=INT(A1+A2)+MOD(A1+A2,1)
Convert back to minutes and seconds
If you put =24+3/60 into each cell, you will have a value of 48.1 in cell A3.
Now you need to convert this back to minutes and seconds. Use the following formula in cell A4:
=MOD(A3,1)*60
This takes the decimal portion and multiples it by 60. Remember, we divided by 60 in the beginning, so to convert it back to seconds we need to multiply.
You could have also done this separately, i.e. in cell A3 use this formula:
=INT(A1+A2)
and this formula in cell A4:
=MOD(A1+A2,1)*60
Here's a screenshot showing the final formulas:
To make life easier when entering multiple dates/times it is possible to use a custom format to remove the need to enter the colon, and the leading "hour" 0. This however requires a second field for the numerical date to be stored, as the displayed date from the custom format is in base 10.
Displaying a number as a time (no need to enter colons, but no time conversion)
For displaying the times on the sheet, and for entering them without having to type the colon set the cell format to custom and use:
0/:00
Then enter your time. For example, if you wanted to enter 62:30, then you would simply type 6230 and your custom format would visually insert a colon 2 decimal points from the right.
If you only need to display the times, stop here.
Converting number to time
If you need to be able to calculate with the times, you will need to convert them from base 10 into the time format.
This can be done with the following formula (change A2 to the relevant cell reference):
=TIME(0,TRUNC(A2/100),MOD(A2,100))
=TIME starts the number to time conversion
We don't need hours, so enter 0, at the beginning of the formula, as the format is always hh,mm,ss (to display hours and minutes instead of minutes and seconds, place the 0 at the end of the formula).
For the minutes, TRUNC(A2/100), discards the rightmost 2 digits.
For the seconds, MOD(A2,100) keeps the rightmost 2 digits and discards everything to the left.
The above formula was found and adapted from this article:
PC Mag.com - Easy Date and Time Entry in Excel
Alternatively, you could skip the 0/:00 custom formatting, and just enter your time in a cell to be referenced of the edge of the visible workspace or on another sheet as you would for the custom formatting (ie: 6230 for 62:30)
Then change the display format of the cells with the formula to [m]:ss as #Sean Chessire suggested.
Here is a screen shot to show what I mean.
If you are using hand inputted data, you can enter your data as mm:ss,0 or mm:ss.0 depending on your language/region selection instead of 00:mm:ss.
You need to specify your cell format as [m]:ss if you like to see all minutes seconds format instead of hours minutes seconds format.
as text:
=CONCATENATE(TEXT(cell;"d");" days ";TEXT(cell;"t");" hours ";MID(TEXT(cell;"hh:mm:ss");4;2);" minutes ";TEXT(cell;"s");" seconds")
5.In the Format Cells box, click Custom in the Category list.
6.In the Type box, at the top of the list of formats, type [h]:mm;# and then click OK. (That’s a colon after [h], and a semicolon after mm.)
YOu can then add hours. The format will be in the Type list the next time you need it.
From MS, works well.
http://office.microsoft.com/en-us/excel-help/add-or-subtract-time-HA102809662.aspx
One convenient trick to entering elapsed times into Excel is to have two zeros and a colon before the number of minutes, details follow. For copy and paste operations into Excel without have to worry about formatting at all one can use the format 00:XX:XX where XX are two digits totaling < 60. In that case, Excel will echo 0:XX:XX in the cell contents displayed and store the data as 12:XX:XX AM. If one pastes data in a 00:XXX:XX format into Excel, or 00:XX:XX where either XX > 59 this will be converted into a fraction of a day.
For example, 00:121:12 becomes 0.0841666666666667, which if multiplied by the number of seconds in a day, 86,400, becomes 7272 s. Next, 00:21:12 would by default show 0:21:12 stored as 12:21:12 AM. Finally, 00:21:60 becomes 0.0152777777777778, also a fraction of a day.
This suggestion is made merely to avoid having to worry about specific formatting in Excel, and letting the program worry about it. Note, for Excel data internally formatted as 12:XX:XX AM one can only use certain Excel commands, for example, one can take an average. However, subtraction will only work when the result is a positive number. Such that converting times into seconds, fractions of a day, or other real number is suggested for access to more complete arithmetic operation coverage.
For example, if one has a column of mixed time formats, or times that are negative and will not display, if one changes the number formatting to General, all the times will be converted to fractions of a day.

Resources