How to get hour and minute a time cell when it is more than 24:00 in EXCEL - excel

When summing multiple excel cells which contain time durations (for instance the duration of the time an employee is present in the office for each day of a month), the sum gets bigger than 24:00 hours and we have to select a specific Type of Time Category in the Number tab in Format Cell (Normally it is named 37:30:55 for clarification). It works fine. But using the typical HOUR and MINUTE functions does not give the right HOUR part and MINUTE part of that summation.
For example in the image attached, the sum of durations is 126:06:00 and we expect the output 126 and 6 when using HOUR(D33) and MINUTE(D33) respectively. The MINUTE function works fine, but seems the HOUR function always gets confused.
Is there any other function that can help solve this issue?

As date/timeis just a double, use this formula:
=INT(A1*24)

Related

Combine (hour, minute, am/pm) columns for two times, then calculate minutes elapsed

I have Time In and Time Out that need to be input on a google sheet. It has to be tracked down to the minute so I have a column for hour, minute, and am/pm. My goal is to have the amount of minutes elapsed between the time in and time out in a row.
I have not found a way to combine all three columns into a time, especially with the am/pm column in the mix. Then subsequently do a formula to find minutes elapsed. I am not well versed in spreadsheet formulas so if there is an easier way of achieving my goal please let me know.
A screenshot is attached of the google sheet columns. Thank you to anyone that can help.
Screenshot of columns :
TIME(HOUR,MINUTES,SECONDS)
That is one formula that you can use to convert integers into time in excel. I do not know if it will work in Google Sheets. I will continue with the excel solution with the assumption the formulas are the same in google sheets or there is an equivalent.
Assuming your data is layed out as per the picture below, you could use the following formulas to convert your time to an actual time that the spreadsheet can use. There are other solutions as well.
=TIME(A1+IF(AND(C1="PM",A1<12),12,0),B1,0)
That will convert your separated times into a spread sheet time. Do the same thing for the OUT Time as below:
=TIME(D1+IF(AND(F1="PM",D1<12),12,0),E1,0)+IF(TIME(D1+IF(AND(F1="PM",D1<12),12,0),E1,0)<TIME(A1+IF(AND(C1="PM",A1<12),12,0),B1,0),1,0)
That whole other part about checking the time and adding 1 or 0 is that if the out time is less, it is assuming the time is the next day. Days are represented by integers, and time is represented by the decimal value.
Now that you have a method for determine both times, subtract the larger time from the smaller time with the formula below in a single cell:
=(TIME(D1+IF(AND(F1="PM",D1<12),12,0),E1,0)+IF(TIME(D1+IF(AND(F1="PM",D1<12),12,0),E1,0)<TIME(A1+IF(AND(C1="PM",A1<12),12,0),B1,0),1,0))-(TIME(A1+IF(AND(C1="PM",A1<12),12,0),B1,0))
ALTERNATE METHOD
Convert everything to minutes, take the difference.
The first time converted to minutes will be:
=(A1+IF(AND(C1="PM",A1<12),12,0))*60+B1
The Second time converted to minutes will be:
=(D1+IF(AND(F1="PM",D1<12),12,0))*60+E1+IF(((D1+IF(AND(F1="PM",D1<12),12,0))*60+E1)<((A1+IF(AND(C1="PM",A1<12),12,0))*60+B1),24*60,0)
Now you just need to take the difference between the minutes in a single cell:
=((D1+IF(AND(F1="PM",D1<12),12,0))*60+E1+IF(((D1+IF(AND(F1="PM",D1<12),12,0))*60+E1)<((A1+IF(AND(C1="PM",A1<12),12,0))*60+B1),24*60,0))-((A1+IF(AND(C1="PM",A1<12),12,0))*60+B1)

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.

How can I extract the hour part from a duration value in Excel?

How can I convert duration in excel to text ? I am having 1037:00:00 in a cell, which is the sum of certain durations. I want to extract 1037 alone. Excel returns "hours" when I try to extract with MID or use TEXT function.
If it is really the sum of some durations you can get the amount of hours by multiplying the cell by 24. The internal representation of a date or time cell is the number of days since beginning of the year 1900, so you have to multiply it by 24 to get the number of hours. (The year 1900 is not interesting for you as you just want a time span.) The Hour function does not work here because you get the day hour which is 5 in this case.
Be sure to format your target cell as regular number.
lets assume your cell with 1037:00:00 is in cell L40. You can use the following formula to pull the hours.
=INT(L40)*24+HOURS(L40)
Note this will only pull full hours rounded down. It does not take into account minutes or seconds.
Alternatives:
=Rounddown(L40*24,0)
This alternative is what Fratyx explained in his answer.

How to get the difference in minutes between two dates in Microsoft Excel?

I am doing some work in Excel and am running into a bit of a problem. The instruments I am working with save the date and the time of the measurements and I can read this data into Excel with the following format:
A B
1 Date: Time:
2 12/11/12 2:36:25
3 12/12/12 1:46:14
What I am looking to do is find the difference in the two date/time stamps in mins so that I can create a decay curve from the data. So In Excel, I am looking to Make this (if the number of mins in this example is wrong I just calculated it by hand quickly):
A B C
1 Date: Time: Time Elapsed (Minutes)
2 12/11/12 2:36:25 -
3 12/12/12 1:46:14 1436.82
I Have looked around for a bit and found several methods for the difference in time but they always assume that the dates are the same. I exaggerated the time between my measurements some but that roll over of days is what is causing me grief. Any suggestions or hints as to how to go about this would be great. Even If I could find the difference between the date and times in hrs or days in a decimal format, I could just multiple by a constant to get my answer. Please note, I do have experience with programming and Excel but please explain in details. I sometimes get lost in steps.
time and date are both stored as numerical, decimal values (floating point actually). Dates are the whole numbers and time is the decimal part (1/24 = 1 hour, 1/24*1/60 is one minute etc...)
Date-time difference is calculated as:
date2-date1
time2-time1
which will give you the answer in days, now multiply by 24 (hours in day) and then by 60 (minutes in hour) and you are there:
time elapsed = ((date2-date1) + (time2-time1)) * 24 * 60
or
C3 = ((A3-A2)+(B3-B2))*24*60
To add a bit more perspective, Excel stores date and times as serial numbers.
Here is a Reference material to read up.
I would suggest you to use the following:
Combine date to it's time and then do the difference. So it will not cause you any issues of next day or anything.
Please refer to the image with calculations. You may leave your total minutes cell as general or number format.
MS EXCEL Article: Calculate the difference between two times
Example as per this article
Neat way to do this is:
=MOD(end-start,1)*24
where start and end are formatted as "09:00" and "17:00"
Midnight shift
If start and end time are on the same day the MOD function does not affect anything. If the end time crosses midnight, and the end is earlier then start (say you start 23PM and finish 1AM, so result is 2 hours), the MOD function flips the sign of the difference.
Note that this formula calculates the difference between two times (actually two dates) as decimal value. If you want to see the result as time, display the result as time (ctrl+shift+2).
https://exceljet.net/formula/time-difference-in-hours-as-decimal-value
get n day between two dates, by using days360 function =days360(dateA,dateB)
find minute with this formula using timeA as reference =(timeB-$timeA+n*"24:00")*1440
voila you get minutes between two time and dates
I think =TEXT(<cellA> - <cellB>; "[h]:mm:ss") is a more concise answer. This way, you can have your column as a datetime.

Adding Two Times Up In Excel

I I'm have small headache caused today by excel and the way it takes control of everything. I have two time values I need to add together then divide by a value I got charged for that time to work out how much it cost me an hour.
so say I was charged day on for 12:30:00
on day 2 I was charged for 13:20:00
and day 3 I was charged for 20:30:00
In total it cost me £1000
The calculation would be
£1000 / (12:30:00 + 13:20:00 + 20:30:00 = 46:20:00)
I would guess to get the answer I would
1000 / Sum(12:30:00+13:20:00+20:30:00) = price per hour
But it doesn't...
I guess I need some sort of convert function on the time or to divide it by 24 to get hours but I'm stuck
Help would be hugely appreciated!
Excel represents times as fractional days, so your function is actually representing the rate per day.
Assuming your times are in cells A1:A3, you can adjust your function to something like:
1000 / Sum(A1:A3) / 24
which will give you the rate per hour (by my calculations, £21.58/hr).
As others have mentioned, you will need to set the cell to a currency format.
Excel should be performing the calculation correctly, but it is just showing as a time. Format the result cell as "number" instead.
You can use the HOUR and MINUTE functions to get the hour and minute portions of the time values, however as lc mentions, you do need to ensure that the formatting of the cell is set to Number, as it will default to a time.
Assuming you have your hh:mm:ss values running down the page (column A), in the next column put the formula
=(A1-INT(A1))*24
underneath this you can put your formula
= 1000 / SUM(A1:A3)
but don't forget to format it as Number.

Resources