Now, that we've learnt how to enter dates and time to your spreadsheet, it's time to talk about the ways of calculating time in Google Sheets. We'll discuss the ways of finding time difference in detail, see how to sum dates and time together, and learn to display only date or time units and set them apart completely.
How to calculate time difference in Google Sheets
When you're working on some projects, it is usually important to control how much time you spend. This is called elapsed time. Google Sheets can help you calculate the time difference in a lot of various ways.
Example 1. Subtract time to get the time duration in Google Sheets
If you have your start time and end time, it's not a problem to find out the time spent:
Let's assume the start time is in column A and the end time is in column B. With a simple subtraction formula in C2, you will find how much time this or that task took:
=B2-A2
The time is formatted as "hh:mm" by default.
To get the results as hours only or as hours, minutes, and seconds, you need to apply a custom format with the corresponding time codes: h and hh:mm:ss. Google even offers a special number format for cases like this - Duration:
Tip. To apply the custom time format, go to Format > Number > Custom number format in your spreadsheet menu.
Example 2. Calculate time duration in Google Sheets using the TEXT function
Another trick to calculate the time duration in Google Sheets involves the TEXT function:
=TEXT(B2-A2,"h")
- for hours
=TEXT(B2-A2,"h:mm")
- for hours and minutes
=TEXT(B2-A2,"h:mm:ss")
- for hours, minutes, and seconds
Note. See how the records are aligned to the left? Because the TEXT function always returns the results formatted as a text. This means these values cannot be used for further calculations.
Example 3. Time difference in hours, minutes, and seconds
You can track the time spent and get the result in one time unit disregarding other units. For example, count the number of only hours, only minutes, or only seconds.
Note. To ensure correct results, your cells should be formatted either as numbers or automatically: Format > Number > Number or Format > Number > Automatic.
-
To get the number of hours spent, subtract your start time from the end time and multiply the result by 24 (since there are 24 hours in one day):
=(End time - Start time) * 24You will get a time difference as a decimal:
If the start time is greater than the end time, the formula will return a negative number, like in C5 in my example.
Tip. The INT function will let you see the number of complete hours spent since it rounds numbers down to the nearest integer:
-
To count minutes, subtract the start time from the end time and multiply whatever you get by 1,440 (since there are 1,440 minutes in one day):
=(End time - Start time) * 1440 -
To find out how many seconds passed between two times, the drill is the same: subtract the start time from the end time and multiply the result by 86,400 (the number of seconds in a day):
=(End time - Start time) * 86400
Tip. You can avoid multiplying in all these cases. Just subtract times first, and then apply elapsed time format from Format > Number > Custom date and time. If you click the down arrow to the right of the text field, you'll be able to choose between additional date and time units:
Example 4. Functions to get the time difference in a Google spreadsheet
As always, Google Sheets equips you with three particularly useful functions for this purpose.
Note. These functions work only within 24 hours and 60 minutes and seconds. If the time difference exceeds these limits, the formulas will return errors.
=HOUR(B2-A2)
- to return hours only (without minutes and seconds)=MINUTE(B2-A2)
- to return minutes only (without hours and seconds)=SECOND(B2-A2)
- to return seconds only (without hours and minutes)
How to add and subtract time in Google Sheets: hours, minutes, or seconds
These operations can also be achieved with two techniques: one involves basic math calculations, another - functions. While the first way always works, the second one with functions works only when you add or subtract units less than 24 hours, or 60 minutes, or 60 seconds.
Add or subtract hours in Google Sheets
-
Add less than 24 hours:
=Start time + TIME(N hours, 0, 0)Here's how the formula looks on real data:
=A2+TIME(3,0,0)
-
Add more than 24 hours:
=Start time + (N hours / 24)To add 27 hours to the time in A2, I use this formula:
=A2+(27/24)
- To subtract 24 and more hours, use the formulas above as a basis but change the plus sign (+) to the minus sign (-). Here's what I've got:
=A2-TIME(3,0,0)
- to subtract 3 hours=A2-(27/24)
- to subtract 27 hours
Add or subtract minutes in Google Sheets
The principle of manipulating minutes is the same as with the hours.
-
There's the TIME function that adds and subtracts up to 60 minutes:
=Start time + TIME(0, N minutes, 0)If you are to add 40 minutes, you can do it like this:
=A2+TIME(0,40,0)
If you are to subtract 20 minutes, here's the formula to use:
=A2-TIME(0,40,0)
-
And there's a formula based on simple arithmetic to add and subtract over 60 minutes:
=Start time + (N minutes / 1440)Thus, here's how you add 120 minutes:
=A2+(120/1440)
Put the minus instead of plus to subtract 120 minutes:
=A2-(120/1440)
Add or subtract seconds in Google Sheets
Seconds in Google Sheets are calculated in the same manner as hours and minutes.
-
You can use the TIME function to add or subtract up to 60 seconds:
=Start time + TIME(0, 0, N seconds)For example, add 30 seconds:
=A2+TIME(0,0,30)
Or subtract 30 seconds:
=A2-TIME(0,0,30)
-
To calculate over 60 seconds, use simple maths:
=Start time + (N seconds / 86400)Add 700 seconds:
=A2+(700/86400)
Or subtract 700 seconds:
=A2-(700/86400)
How to sum time in Google Sheets
To find the total time in your table in Google Sheets, you can use the SUM function. The trick here is to choose the correct format to display the result.
By default, the result will be formatted as Duration - hh:mm:ss
But most often the default time or duration format won't be enough, and you will need to come up with your own one.
A7:A9 cells contain the same time value. They are just displayed differently. And you can actually perform calculations with them: subtract, sum, convert to decimal, etc.
Extract date and time from a full "date-time" record
Let's imagine that one cell in Google Sheets contains both, date and time. You want to set them apart: extract only the date to one cell and only time to another.
Split Date time using Number format
In order to display date or time in one cell on your screen or to print it, just select the original cell, go to Format > Number and choose Date or Time.
However, if you'd like to use these values for future calculations (subtract, sum, etc.), this won't be enough. If you don't see the time unit in a cell, it doesn't necessarily mean that it's absent, and vice versa.
So what do you do?
Split Date time using formulas
Google stores dates and time as numbers. For example, it sees the date 8/24/2017 11:40:03 as the number 42971,4861458. The integer part represents the date, the fractional - time. So, your task is down to separating integer from fractional.
- To extract date (integer part), use the ROUNDDOWN function in cell B2:
=ROUNDDOWN(A2,0)
The formula rounds the value down and casts the fractional part away.
-
To extract time, place the following subtraction formula into C2:
=A2-B2
- Copy the results into the third row and apply Date format to B3 and Time format to C3:
Use the Split Date & Time add-on
You may be surprised but there's one special add-on for this job. It's really small and easy but its contribution to Google Sheets cannot be overstated.
Split Date & Time splits all Date time records in your entire column at once. You control the desired outcome with just 4 simple settings:
You tell the add-on:
- Whether there's a header row.
- If you want to get the Date unit.
- If you want to get the Time unit.
- And if you'd like to replace your original column with the new data.
It literally takes the burden of splitting date and time units off your shoulders:
The add-on is part of the Power Tools collection so you will have more than 40 other useful add-ons at hand:
These are the ways to not only display date or time, but to separate them to different cells. And you can perform various calculations with these records now.
I hope these examples will help you solve your tasks when working with dates and time in Google Sheets.
Spreadsheet with formula examples
Calculating time in Google Sheets (make yourself a copy to practice)
393 comments
Hello!
I'm using sheets to help track the pay for our nanny we share with another family. I need help figuring out shared time. Our nanny gets paid $25/hr, but when it's both kids together, the families split the bill to pay $12.50/hr each. Some days are just one kid, so that family just pays $25/hr for the whole day. Some days are one kid in the morning, the second kid comes for a few hours in the afternoon, and then the last few hours with just the first kid. So one family pays the morning as $25/hr, the shared time as $12.50, and the last hours as $25/hr; the second family pays just $12.50/hr for the shared time. Both kiddos do this pattern, so either one might have more time in than the other (meaning a superset as a default assumption didn't work.)
How do I ask sheets to find the amount of time the two kids shared? I can have separate "time in" and "time out" columns for each kid, but setting a formula to calculate the overlapping hours has been so tricky that we've just been doing it by hand!
Appreciate the help!
Rose
Hello Rose,
I'm sorry it's hard to provide any formula because I have no idea how your data is arranged. For me to be able to help you, please share a small sample spreadsheet with me (support@apps4gs.com) with 2 sheets: (1) a copy of your source data (2) the result you expect to get. The result sheet is of great importance as it gives a better understanding than any text description.
I also kindly ask you to shorten the tables to 10-20 rows.
Note. We keep that Google account for file sharing only and don't monitor its Inbox. Do not email there. Once you share the file, just confirm by replying to this comment.
I'll look into your task and try to help.
Hi Natalia, hope you're doing well!!
I have a cell with a data just like 18/08/2023 11:12:00 (Cell FM3) and another cell with the numer of working hours = 48 (Cell FN3). In another sheet i have a list with the holidays troughout the year, and i consider 08h and 30 minutos as working hours per day.
Is there any how to calculate de date + 48 working hours, considering 8h and 30 minutes per day? I've tried everything but i couldn't get by....
Thanks!!
Hi John,
Can you please specify what result exactly you want to achieve? What should the formula show as a result?
Hello, Natalia! Sorry if I couldn't be clear enough. I would like a formula for Google Sheets that adds 48 working hours to the FM3 cell that contains "18/08/2023 11:12:00". For example, if we consider 48 running hours, the formula would return "20/08/2023 11:12:00", but I would like to specify working hours, where working hours for me are from 08:00 to 12:00, and from 1:30 pm until 6:00 pm. (12:00 - 13:00pm lunch time). In other words, the total number of working hours per day, from 8:00 am to 6 pm, is 8:30 (8h 30min). I've done a lot of research, but you're the only person on the entire internet who seems to be able to accomplish this formula! Thanks for replying!
Thank you for additional explanation, John! Could you please share a sample table with me (support@apps4gs.com)? Understanding how your data is arranged will help me find the most suitable solution for you.
Note. We keep that Google account for file sharing only and don't monitor its Inbox. Do not email there. Once you share the file, just confirm by replying to this comment. Thank you.
Just sent! Thank you very much for your support!!!
Hi John,
I'm sorry I don't see any file shared from you. To grant me access to your data, press the Share button at the upper right corner of Google Sheets and enter support@apps4gs.com to share the file directly. Thank you.
Hi just want to ask what to do here because I have tried the formula for the other cells but it wont get the total number of hours. for example a total number of worked hours in one month is 240 hours, I have input 12 hours each day, for example I put 12 hours for 5 days and one day for 9 hours, and when you total it it will show negative sum. together with other. but the other cells are accurate
Hi claire,
In what format do you enter those hours? How is your cell with the resulting formula formatted? What formula exactly are you trying to use?
Hello, I am wanting to create a time sheet for some fellow employees but I cannot find a formula that shows how to get the total hours worked from doing the clock in, out, in, out for their lunch breaks (example: in 6:45 am, out 1:20 pm, in 2:05 pm, out 5:20 pm = 9 hours and 50 minutes worked) I cannot get it to equal the time total worked with any formula I have tried. Please let me know if there is a way to do that.
Hello samantha,
Just calculate the time difference between the start time and end time as shown in this part of the article and then subtract the lunch:
=D2-A2-(C2-B2)
Hi there,
I'm trying to efficiently figure out my employees hours worked and pay for those hours. So I have figured out how to subtract time started from time ended and then how do I translate that time- back to hours so I can multiply that by their hourly pay. For example:
Employee 1: Clock In- 16:15 Clock Out- 21:30 and get 5:15 then I try to multiply this number by $18/hr and am getting a wacky number. any advice??
Hi Beth,
Try to multiply your time difference by 24 to get the result as a decimal first. Then it will multiply by an hourly rate correctly. Please see this section for formula examples: Time difference in hours, minutes, and seconds
Natalia, firstly you are a wizard when it comes to this! Thanks for your help in advance!
Here's the layout of my timesheet (that gets fed from the form)
Timestamp Name Email Your Position Date Completed Time Started Time Completed Hours worked
2/6/2024 17:06:06 sample sample 2/5/2024 3:45:00 PM 5:00:00 PM 1.15
I'm trying to have the sheet calculate the hours worked working with the AM PM time - is that possible?
Appreciate your lovely words, Avi!
For your task, you need to subtract time started from time completed (and multiply it by 24 if you'd like to get the result as a decimal). See this section for formulas examples: Time difference in hours, minutes, and seconds
Hi Natalia, I am building a google sheets that allow me to arrange schedule for employees.
After we key in time in and time out, I already make it to be able to auto calculation for us to count the total working hours. But besides that, I need your help on this:
If the working hours is more than 7.5hours, need to minus one hour break time.
If the working hours is less than 7.5hours, no need to minus any break time.
How do I do that? Kindly assist.
Thank you so much.
Hello KY,
The IF function will help you check if the working hours are more/less than 7.5 hours and add or subtract the required amount of time correspondingly.
Hi There,
I am building a sheet that will allow me to calculate a "premium" on an employees hourly rate based on the time of day. For example, depending on the time of day, the employee may make an additional 10% or 20% premium. The goal of the grid I am building, is to allow a user to enter someone's start time, have the remaining hours auto populate (using the time function to add an hour to each previous hour) and then use an IF AND function to check whether each hour is within a certain "premium" window and then apply said premium to their hourly.
I am using the following formula to auto populate the hours, adding one hour to the previous hour: =B5+TIMEVALUE("01:00:00") Note: I have also used the TIME function interchangeably to no avail.
I am using the following formula to evaluate the hour and determine which premium, if any, to apply to the hourly rate: =IF(AND($B6=TIMEVALUE("07:00:00")),$B$3*1,IF(AND($B6>=TIMEVALUE("20:00:00"),$B6=TIMEVALUE("00:00:00"),$B6<TIMEVALUE("07:00:00")),$B$3*1.2,"FALSE")))
Unfortunately, when the hours cross over from prior to midnight to after midnight (i.e. 11pm to 1am), the time evaluation formula does not detect any of the hours as falling between the 12:00am to 7:00am window, which should apply a 20% premium.
Any idea's how to adjust either formula to allow for this?
Hi Zach,
For me to be able to help you better, please share a small sample spreadsheet with us (support@apps4gs.com) with 2 sheets: (1) a copy of your source data with your formula (2) the result you expect to get. I kindly ask you to shorten the tables to 10-20 rows.
Note. We keep that Google account for file sharing only and don't monitor its Inbox. Do not email there. Once you share the file, just confirm by replying to this comment.
I'll look into your task and try to help.
Thanks Natalia! I have shared a sample sheet.
Thank you for creating a sample, Zach!
I entered another formula that works in the copy of the sheet, please take a look:
=IF(AND(HOUR($B5)<20,HOUR($B5)>=7),$B$3*1,IF(AND(HOUR($B5)>=20,HOUR($B5)<=23),$B$3*1.1,IF(AND(HOUR($B5)>=0,HOUR($B5)<7),$B$3*1.2,"FALSE")))
It looks like TIMEVALUE still accounts for dates (though its stated in its Help that dates are ignored) because your formula works as soon as I clear B5 and no time units seem to fall to "another day" (with 00:00) anymore. Anyways, the HOUR function solves this problem.
Thank you so much Natalia! You are THE BEST!
My pleasure, Zach! π
Hi Natalia
I'm trying to get the duration of 2 cells showing an event's start time and end time, but I want the format to be in days, hours, and minutes. for example the duration should be displayed as follows: 2 days 4 hours 34 minutes. What formula can I use?
Hi Rose,
Please try this formula:
=IF(B2>A2,CONCATENATE(DATEDIF(A2,B2,"D")&" days ",TEXT(MOD(B2-A2,1),"hh")," hours ",TEXT(MOD(B2-A2,1/24),"mm")," minutes"),"")
I have tried to use the formula you gave above, however, the formula keeps giving me 12 minutes for all the differences in time. I've tried to copy the example below so you can understand.
17/01/2024 12:20 18/01/2024 08:11 1 days 19 hours 12 minutes
18/01/2024 09:34 18/01/2024 10:49 0 days 01 hours 12 minutes
18/01/2024 11:24 18/01/2024 11:29 0 days 00 hours 12 minutes
18/01/2024 11:42 18/01/2024 12:04 0 days 00 hours 12 minutes
18/01/2024 12:06 18/01/2024 13:59 0 days 01 hours 12 minutes
18/01/2024 11:59 18/01/2024 14:01 0 days 02 hours 12 minutes
18/01/2024 14:35 18/01/2024 14:39 0 days 00 hours 12 minutes
18/01/2024 16:36 18/01/2024 16:38 0 days 00 hours 12 minutes
18/01/2024 00:06 19/01/2024 09:07 1 days 09 hours 12 minutes
for the example above, I used the formula below. I'm not sure if I'm writing it wrongly or otherwise. Please kindly advise
=IF(H60>G60,CONCATENATE(DATEDIF(G60,H60,"D")&" days ",TEXT(MOD(H60-G60,1),"hh")," hours ",TEXT(MOD(H4-G4,1/24),"mm")," minutes"),"")
Hi Rose,
Thank you for providing the sample. Try this formula instead:
=INT(H60-G60) & " days " & HOUR(H60-G60) & " hours " & MINUTE(H60-G60) & " minutes"
This worked perfectly. thanks a lot Natalia
You're most welcome, Rose!
Hi
Is there also a formula that compares the Start_Date, End_Date, Start_Time , End_Time (4 columns) to the current Date/time (with =NOW() function) with a return of TRUE or FALSE in a seperate column
thx
Hi Peter,
Do you need TRUE if any of the times/dates are the same as current ones? Or if all at the same time? Or only start ones or end ones?
Also, are you aware of the fact that NOW() is a volatile function? Meaning each time you make edits to your sheet, it recalculates itself and so do other formulas using NOW() returning different results each time.
Hi Natalia,
I need a TRUE if the current date and time matches the start date/end date & start time/end time. e.g
Column/Row A1: start date: 06-02-2024
Column/Row B1: end date: 06-02-2024
Column/Row C1: start time: 07:00 (AM)
Column/Row D1: end time: 13:00 (PM)
Column/Row E1: TRUE (if date/time match)
I'll do a HTTP GET Request for a lookup into this file. Google sheets sees the current date/time and compares it to the date/time within the sheet. If there is a match, I get a TRUE back
thx for the reply
Peter
Hi Peter,
Sorry, I still don't understand whether you need OR or AND logic :)
But feel free to try and adjust this formula. It will return true if either start OR end date AND time are the same as the current one.
=IF(OR(AND(TODAY()=A1,TIMEVALUE(TEXT(NOW(),"hh:mm"))=TIMEVALUE(C1)),AND(TODAY()=B1,TIMEVALUE(TEXT(NOW(),"hh:mm"))=TIMEVALUE(D1))),TRUE,FALSE)
Hi Natalia, thanks for your help, I need a formula that checks if the current date and time is correspondend with the values included in the 4 columns, if so then a TRUE back as a Result e.g:
Current Date/Time = 07-02-2024:17:00:00 Start_Date | End_Date | Start_Time | End_Time | Result
07-02-2024 07-02-2024 10:00 19:00:00 True
07-02-2024 07-02-2024 19:00 23:59:00 False
thx
Peter
Thank you for the example of the expected result, Peter.
So basically you want to see TRUE if the current time falls between start and end time and the today's date also falls between the start/end dates? If so, this formula should do the trick:
=IF(AND(TODAY() >= A2, TODAY() <= B2, TIMEVALUE(TEXT(NOW(), "HH:mm:ss")) >= C2, TIMEVALUE(TEXT(NOW(), "HH:mm:ss")) <= D2), TRUE, FALSE)
πyes this is perfect thank you for the super good help and expertise
I appreciate this
Me pleasure, Peter! π
Is there a formula to find the number of occurrences of interval range of time between two columns.
Hello Vibina,
Please describe your task in detail, I'll try to help.
Dear all
I would like to make a schedule for production tasks in a weekly production plan. So for every product there is number of working hours
A-4h
B-15h
C-22h.....
and then I would like to calculate if I work from Monday 8am, and shift is 8 hours when will every product be finished?
Hello Milos,
Though I can't create a schedule for you, I can suggest functions that may help you with the task:
Hope these help!
Hi Natalia,
I enjoyed reading your blogs. May I ask your help if this is possible:
Is there a way to to get the sum of hours in google sheet per cell if I the value per cell is not a number but a "text" and that the assumption is each cell with a "text" value equates to 15 mins. Does that make sense?
Thanks!
Hi Rico,
Thank you for your feedback!
Since Google Sheets can't calculate text, I believe you'll still need some helper table showing the time for each text so you refer to it in your formulas. But I'll be able to suggest better if you provide a few examples of the data you have, how you want to calculate it and what should be as a result.
Tracking Number of Minutes Late from Scheduled Time on Sheets
Hello Ravneet,
I believe this simple subtraction will do the trick for you.
I am trying to create a time sheet in google sheets for multiplue people using rows So I have used the following to find the total time work (duration)
using this formula =SUMPRODUCT((MOD(COLUMN(F5:N5) - COLUMN(E5), 2) = 1),(F5:N5 - E5:M5), F5:N5)
with the following info
E5=5:00 Start time
F5=13:00 End Time
G5=6:00 Start Time
H5=13:00 End Time
I5=7:00 Start Time
J5=17:00 End Time
K5=7:30 Start Time
L5=14:00 End Time
M5=6:00 Start Time
N5=13:00 End Time
Gives me a total time duration of 22:47:30
When the total should be 38:30:00
What have I done wrong?
I have also tried
=SUMPRODUCT((MOD(COLUMN(F5:N5) - COLUMN(E5), 2) = 1) * (F5:N5 - E5:M5 > 0), F5:N5)
Hello Erik,
Please try this formula:
=ARRAYFORMULA(SUM(TIME(HOUR({F5, H5, J5, L5, N5}), MINUTE({F5, H5, J5, L5, N5}), 0) - TIME(HOUR({E5, G5, I5, K5, M5}), MINUTE({E5, G5, I5, K5, M5}), 0)))
That worked. What is the difference between that and what I was doing? Also If I want to expand it out for the entire row I just put the rest of the columns in where they go?
I'm glad it helped!
I used TIME to tell Google Sheets what time units are these exactly (it literally converts them to time format before summing up). And it's more straightforward.
In yours, there's no obvious conversion and Google Sheets may interpret some units incorrectly.
And you're right about adding columns to their places in the formula if you expand the data to the entire row :)
hi first of all im sorry for my broken english but i hope there's someone here who have the answer is this possible to calculate in spreadsheet/excel,
so, i need to calculate how long someone replying chat, but i have to exclude or ignoring break time and before office hours. for example, we start at 09.00 and have break time at 12.00-13.00, so let's say someone chating me at 11.53 and i reply at 13.03, so i just want to show 10 minutes ( from 7 mins before 12.00+3 mins after 13.00), or any advice how to solve this in spreadsheet/excel??
Hi lita,
If you work in Google Sheets & your chat start time is in A2, reply time start is in B9, this formula will help:
=IF(OR(A2>=TIME(13,0,0),B2<=TIME(9,0,0)),0,MAX(MIN(B2,TIME(12,0,0))-MAX(A2,TIME(9,0,0)),0)+MAX(MIN(B2,TIME(17,0,0))-MAX(A2,TIME(13,0,0)),0))
You will learn more about the IF function in this article.
Hi,
I am calculating hours and it is showing 9:30 aka 9 hours and 30 minutes. How do I convert 99:30 to be 99.5 hours instead?
Hi Haylie,
You will find example of how to calculate hours in decimal in the 3rd example here.
I try to calculate the duration between 11pm and the day after 2am, which should be 3 hours, but when I use the duration format, it gives me 19h as it calculate from the same day and not the day after...
How to do this? Thank you so much for your help
Hello Benoit,
If you're trying to get the time duration, just make sure to add dates to the time units as well so Google Sheets calculates everything correctly.
Thank you so much Natalia. You are awesome!
: )
My pleasure :)
Hi Natalia,
I'm having an issue where I typed in the "am" and "pm" into my cells and now when I subtract them it is not finding the duration between the times. Instead, it is taking the hours and minutes from the second cell (the one I'm subtracting) and going back in time by that amount. I tried getting rid of the am and pm to do the math instead but it just comes right back after I erase it in the cell.
Hope I explained it well. Have your encountered this issue? I'm on Mobile by the way.
An update on this, I found out that on the desktop version you can highlight the cells, then go to format -> duration to calculate the duration instead. I'm still not sure how to fix it on Mobile, but I can fix it when I get home. Hope this helps someone!