Aaron Rip
Aaron Rip

Reputation: 41

How do I add duration to a time in 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.

Upvotes: 4

Views: 6443

Answers (2)

phantom99
phantom99

Reputation: 11

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 (; }

Upvotes: 1

Saubhagya
Saubhagya

Reputation: 163

=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).

Upvotes: 0

Related Questions