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.
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.
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:
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 > More Formats > Custom number format in your spreadsheet menu.
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.
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):
You 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, substitute the start time from the end time and multiply whatever you get by 1,440 (since there are 1,440 minutes in one day):
To find out how many seconds passed between two times, the drill is the same: substitute the start time from the end time and multiply the result by 86,400 (the number of seconds in a day):
Tip. You can avoid multiplying in all these cases. Just subtract times first, and then apply elapsed time format from Format > Number > More Formats > More date and time formats. 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:
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)
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 less than 24 hours:
Here's how the formula looks on real data:
Add more than 24 hours:
To add 27 hours to the time in A2, I use this formula:
=A2-TIME(3,0,0) - to subtract 3 hours
=A2-(27/24) - to subtract 27 hours
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:
If you are to add 40 minutes, you can do it like this:
If you are to subtract 20 minutes, here's the formula to use:
And there's a formula based on simple arithmetic to add and subtract over 60 minutes:
Thus, here's how you add 120 minutes:
Put the minus instead of plus to subtract 120 minutes:
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:
For example, add 30 seconds:
Or substitute 30 seconds:
To calculate over 60 seconds, use simple maths:
Add 700 seconds:
Or substitute 700 seconds:
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.
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.
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?
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.
The formula rounds the value down and casts the fractional part away.
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:
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 30 other useful add-ons at hand. Install it from the Google Sheets store to test everything out.
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.
Table of contents