How do I add duration to a time in Google Sheets? - google-sheets

I've found a few answers to questions similar to this elsewhere, except with adding or subtracting two times to get a duration, however, I haven't been able to figure it out enough to meet what I want.
I'm trying to get the time that I woke up using the time that I went to bed and the duration. I've tried doing [Time] + [Duration], however when I do that I get a value like 10060:25:00. I've also tried adding the hour value of the duration and the hour value of the time and dividing by 24, but that didn't work either. I did figure out the minutes though, all I did was =MOD([Time minute value]+[Duration minute value],60).
So to clarify, I just need to find the hour value now.

I am not exactly sure if this answers your question, but I think it is very similar. And I apologise in advance for an unnecessarily complicated description.
Sorry I didn't have time to provide a shorter answer.
I wanted to create a run sheet for a workshop with session durations.
I have a start time, and each session has a duration. I can then calculate start time for next session and cumulative duration of the sessions.
column label :> A || B || C || D
Heading label:> start_time || duration || hidden_duration || Elapsed
Number format:> date/time || number || duration ||duration
new start_time=previous_start_time+hidden_duration
hidden_duration=if(isblank(duration),"0:00:00","0:"&duration)
It seems time is particular about how it interprets a number. This is where the duration format fits in, as it formats correctly to add to time. However, a field formatted as a "duration number format", must then be entered as a duration. In other words, it is expected as 00:00:00.000 which is very particular. Or in fact, it appeared it at least needed 00:00 i.e. Hours and minutes separated by colon.
As I only had minutes, I didn't want to have to enter in this particular format all the time; and if I was to put 5 in the duration field, it was being interpreted as 5 milliseconds (or something). So I have used a simple number in the duration field and inserted it into a string in the hidden_duration field to form 0:duration. For example to add 5 into the minutes column of the hidden_duration entry it would be "0:"&5. The if(isblank(),...test was necessary to avoid blank durations voiding all the way down the column. i.e. If duration was blank, add 00:00:00 time to the start_time.
Start_time Duration Hidden_duration Elapsed
08:30:00 15 =if(isblank(B2),"0:00:00","0:"&B2&":00") =C2
=A2+C2 5 =if(isblank(B3),"0:00:00","0:"&B3&":00") =D2+C3
Drag the second row down to repeat however many entries you will have.
Don't forget to make the appropriate columns the correct number formats.
Also, you can modify the duration formats using Format | Number | More formats| Custom Number Formats and removing the unwanted display fields (such as seconds).
Then, I also made some conditional formatting rules, so that if a duration was blank, the Elapsed and time cells were white text on white background so they looked blank.
For your application you could do the same but have separate hours and minutes columns to make for easy data entry, both being used in the "hidden_duration" formula.
I hope I have helped here, as I found your question, trying to do the same and Googling an answer, but then ended up experimenting and discovering some new things myself.
Someone more knowledgable may be able to correct my entry or make more efficient. {Or at least explain more efficiently (; }

=HOUR(B2-A2)+(MINUTE(B2-A2)/60)
Basically, being B2 the end time and A2 the start time, you subtract B2-A2 and get the hour from the subtraction. Then you do the same and get the amount of minutes. After you have both, you sum the amount of hours with the amount of minutes divided by 60 (to get it in hours).
Don't forget to use the 24-hour format (i.e. 10:00 or 22:00).

Related

How can I calculate rate (events per minute) in Google Sheets?

I am working on creating a spreadsheet template for a video observation tool that my organization will use. Specifically, we will watch ~20-minute long videos, and record the rate (occurrences per minute) of certain behaviors within subsections of the video. For example, "in the clip from 2:06 to 4:30, the speaker asked the audience an average of 2.5 questions per minute."
I think it would be easiest for users to denote individual clips by providing start and end times (e.g. Start: 22:40 End: 23:02). Users should be able to input a count of certain occurrences, and then the spreadsheet will divide that number by the time elapsed and calculate a rate per minute. That is to say, if the speaker asked 8 questions between the timestamps 22:40 and 24:20, the spreadsheet should return a value of 8/(1.67 minutes) = 4.8 questions per minute.
I'm having trouble figuring out a way to enter time values in Google Sheets without it treating them as actual times in a 24-hour day. For example, 22:40 shouldn't refer to 00:22:40am nor to 10:40pm; I just mean 22 minutes and 40 seconds. I guess in theory, I would need it to treat the End Time as x-many minutes (or fractions of a minute) after a given Start Time, so it would need to calculate the total number of seconds elapsed between two mm:ss values and divide that sum by 60 to get the time elapsed in minutes. Then, I could simply divide the count of occurrences (e.g. 8 questions) by that number (1.67 minutes), and get my answer.
Does anyone have any tips about how this could be done? Thank you so much for your help!!
Current State:
Start Time: 22:40
End Time: 24:20
Questions Asked: 8
When I enter =8/(End Time - Start Time), I get 0:00 for some reason. I want it to return 4.8.
Format those durations as Format > Number > Duration. Enter durations complete with elapsed hours, minutes and seconds, as in 0:22:40 and 0:24:20.
You can then calculate events per minute like this:
=E2 / 24 / 60 / (T2 - S2)
...where E2 is the total number of events, S2 is the start moment, and T2 is the end moment.
Format the formula cell as Format > Number > Number.
See this answer for an explanation of how date and time values work in spreadsheets.

Calculating sleep duration (before and after midnight) in Google Sheets

I am trying to calculate the total number of minutes spent in bed overnight by inputting the time entered bed (e.g. 9pm) and time exited bed (e.g. 6am).
Using those example inputs, the answer should be 9hours, or 540minutes (9*60).
Instead, my formula counts backwards, grabbing the duration from 6am to 9pm which is 15hours, or 900min.
Here is what I have so far. The formula on F2 works just fine until you cross midnight in C2. For example, if B2 is 9pm and C2 is 11pm, F2 is 120minutes. Once you change C2 to 12pm (0:00 in 24hour notation), the calculation flips and becomes 540minutes.
I'm thinking since the cells like to count backwards, I could maybe take 24 hours and subtract it by the value in F2, effectively getting back the other portion?
I stumbled into a weird pseudo-fix: if B2 is 21:00 (9pm) and I put 30:00 into C2, C2 displays 6:00 and F2 counts properly. Here is what that looks like. I am hoping to find a better solution than this-- the UX i'm looking to achieve is just putting my bed time and my wake time and the cells do the rest.
Thanks in advance!!
Drop the abs.
C2-B2
already assumes next day when C2<B2 as shown here:
The reason it works is that Google Sheet treats those as (duration of) time. And when displaying time, the "minus amount" is converted to a positive time value that represents a time of the previous day, as if modulus 24 hours. For example, 7:00 (hour) minus 21:00 (hour) gives -14:00 (hour) and it will be displayed as 24:00 (hour) - 14:00 (hour) = 10:00 (hour). Thus it is equivalent to the number you are looking for. However, modulus 24 hours effect is only for display. The minus sign is still inherent to the resultant value.
In order to display minutes or do other calculations with the result, you can wrap it with timevalue(). With that, the underlying value will be converted as described above.
To then display minutes, you can format the cell to display Elapsed minutes using the steps shown below.
And you will see minutes in the cell as shown below.
Your question implies that you may desire to do calculations on the result.
If that is that case, it helps to know that the output of timevalue is time duration in (fractions of) days without any inherent formatting. If not, you may skip the followings.
For example, in the preceding image, if you put =C1*2 in D1, with automatic formatting, D1 will inherit the format of C1, which was Elapsed minutes. You will thus see 1440. However, the actual underlying value is 1 because the real meaning of the data is half a day times 2. And you can confirm that by setting the format of D1 as numbers.
Thus, if you are only doing calculations with outputs of timevalue, you are fine without worrying about the above. However, if you mix the result of timevalue with other types of data, the fraction of day meaning is what will be used in your calculations.

Google sheets convert Decimal(0-100) to minutes(0-60)

I have a spreadsheet that receives data from an RPA, this data is HH:MM, the output is based on how long a task has taken to perform.
example:
Project
Time
Task 1
2:35
Task 2
3:45
Where 2:35 is equal to 2 hours and 35 minutes.
The issue that i am having is that when I add these numbers google sheets displays it as 5:80, where it should be 6:20, as that is the actual amount of hours and minutes represented in the table. In other words I would like the decimal counter to stop at 60 and add new, not at a 100?
Anybody have an idea of how to achieve this? :)
-- Toby
In order for the duration formatting to work the delimeter must be the correct standard according to the language you are working in.

Google Sheets - Chart Duration Error

I am trying produce a burn chart in google sheets to record time remaining on a project, which has to be formatted as 'duration' but any data over 24 hours plots incorrectly.
It seems to be wrapping values over 24 hours back on themselves, so for example 30:00:00 plots at 06:00:00 (which is 30-24). So it seems to be treating the 'duration' as if they're numbers on a clock when I need them to work as normal numbers - i.e. go over 24 hours.
Here's the Sheet
and a screenshot:
Can anyone help?
It seems you found a bug in Google Sheets, googling for the problem finds other people with the same issue, e.g. here: https://productforums.google.com/forum/#!topic/docs/tf_ehe6J-CU
The workaround is to multiply the values by 24 to get the hours as a number. It will not be perfect, as it will show fractions of an hour after the dot, instead of proper minutes (you could implement a text formula to get the minute values e.g. as data point values if you really want to, but probably not on the Y axis). For most real life projects I'm guessing that should be good enough.

Getting the hours of a duration type cell in google sheets

I have a cell with a duration type field that is marking 25:30:00. I need to convert this to a decimal type of hours. So I would need 25.5 hours. However I cannot find any way of getting the number of hours from the field. Splitting the string by : does not work in a custom function neither does the function HOUR. So how can I do this.
PD: I've found this question How do I get the number of days for a duration where the number of hours exceeds 24 in google sheets? which seems very close to what I want but I can't figure out how to adapt it to my needs. Any help would be apprecaited.
Duration is represented in Google Sheets by a number that measures the duration in days. (You can see this by changing the format of a cell with duration to a number.) This is why multiplying it by 24, as pnuts suggested, gives the duration expressed in hours. I'd suggest also using N to make the result explicitly a number:
=N(A2*24)
(Assuming duration is in A2). This should eliminate the need to manually format the output as a number.

Resources