How to calculate time in Excel - time difference, adding / subtracting times

This tutorial focuses on various ways to calculate times in Excel. You will find a few useful formulas to add and subtract times, calculate time difference, or elapsed time, and more.

In the last week's article, we had a close look at the specificities of Excel time format and capabilities of basic time functions. Today, we are going to dive deeper into Excel time calculations and you will learn a few more formulas to efficiently manipulate times in your worksheets.

How to calculate time difference in Excel (elapsed time)

To begin with, let's see how you can quickly calculate elapsed time in Excel, i.e. find the difference between a beginning time and an ending time. And as is often the case, there is more than one formula to perform time calculations. Which one to choose depends on your dataset and exactly what result you are trying to achieve. So, let's run through all methods, one at a time.

Formula 1. Subtract one time from the other

As you probably know, times in Excel are usual decimal numbers formatted to look like times. And because they are numbers, you can add and subtract times just as any other numerical values.

The simplest and most obvious Excel formula to calculate time difference is this:

=End time - Start time

Depending on you data structure, the actual time difference formula may take various shapes, for example:

Formula Explanation
=A2-B2 Calculates the difference between the time values in cells A2 and B2.
=TIMEVALUE("8:30 PM") - TIMEVALUE("6:40 AM") Calculates the difference between the specified times.
=TIME(HOUR(A2), MINUTE(A2), SECOND(A2)) - TIME(HOUR(B2), MINUTE(B2), SECOND(B2)) Calculates the time difference between values in cells A2 and B2 ignoring the date difference, when the cells contain both the date and time values.

Remembering that in the internal Excel system, times are represented by fractional parts of decimal numbers, you are likely to get the results similar to this: Calculating time difference in Excel

The decimals in column D are perfectly true but not very meaningful. To make them more informative, you can apply custom time formatting with one of the following codes:

Time code Explanation
h Elapsed hours, display as 4.
h:mm Elapsed hours and minutes, display as 4:10.
h:mm:ss Elapsed hours, minutes and seconds, display as 4:10:20.

To apply the custom time format, click Ctrl + 1 to open the Format Cells dialog, select Custom from the Category list and type the time codes in the Type box. Please see Creating a custom time format in Excel for the detailed steps.

And now, let's see how our time difference formula and time codes work in real worksheets. With Start times residing in column A and End times in column B, you can copy the following formula in columns C though E:

=$B2-$A2

The elapsed time is displayed differently depending on the time format applied to the column: The elapsed time is displayed differently depending on the applied time format.

Note. If the elapsed time is displayed as hash marks (#####), then either a cell with the formula is not wide enough to fit the time or the result of your time calculations is a negative value.

Formula 2. Calculating time difference with the TEXT function

Another simple technique to calculate the duration between two times in Excel is using the TEXT function:

  • Calculate hours between two times:

    =TEXT(B2-A2, "h")

  • Return hours and minutes between 2 times:

    =TEXT(B2-A2, "h:mm")

  • Return hours, minutes and seconds between 2 times:

    =TEXT(B2-A2, "h:mm:ss")

Calculating time difference with TEXT function

Notes:

  • The value returned by the TEXT function is always text. Please notice the left alignment of text values in columns C:E in the screenshot above. In certain scenarios, this might be a significant limitation because you won't be able to use the returned "text times" in other calculations.
  • If the result is a negative number, the TEXT formula returns the #VALUE! error.

Formula 3. Count hours, minutes or seconds between two times

To get the time difference in a single time unit (hours ,minutes or seconds), you can perform the following calculations.

Calculate hours between two times:

To present the difference between two times as a decimal number, use this formula:

=(End time - Start time) * 24

Supposing that your start time is in A2 and end time in B2, you can use a simple equation B2-A2 to calculate the difference between two times, and then multiply it by 24, which is the number of hours in one day:

=(B2-A2) * 24

To get the number of complete hours, use the INT function to round the result down to the nearest integer:

=INT((B2-A2) * 24) Calculating hours between two times in Excel

Total minutes between two times:

To calculate the minutes between two times, multiply the time difference by 1440, which is the number of minutes in one day (24 hours * 60 minutes = 1440).

=(End time - Start time) * 1440

As demonstrated in the following screenshot, the formula can return both positive and negative values, the latter occur when the end time is less than the start time, like in row 5:

=(B2-A2)*1440 Calculating total minutes between two times in Excel

Total seconds between times:

To get the total seconds between two times, you multiply the time difference by 86400, which is the number of seconds in one day (24 hours * 60 minutes * 60 seconds = 86400).

=(End time - Start time) * 86400

In our example, the formula is as follows:

=(B2-A2)* 86400 Calculating total seconds between two times

Note. For the results to display correctly, the General format should be applied to the cells with your time difference formula.

Formula 4. Calculate difference in one time unit ignoring others

To find the difference between 2 times in a certain time unit, ignoring the others, use one of the following functions.

  • Difference in hours, ignoring minutes and seconds:

    =HOUR(B2-A2)

  • Difference in minutes, ignoring hours and seconds:

    =MINUTE(B2-A2)

  • Difference in seconds, ignoring hours and minutes:

    =SECOND(B2-A2)

When using Excel's HOUR, MINUTE and SECOND functions, please remember that the result cannot exceed 24 for hours and 60 for minutes and seconds. Calculate time difference in one unit ignoring others

Note. If the end time is less than the start time (i.e. the result of the formula is a negative number), the #NUM! error is returned.

Formula 5. Calculate elapsed time from a start time to now

In order to calculate how much time has elapsed since the start time to now, you simply use the NOW function to return today's date and the current time, and then subtract the start date and time from it.

Supposing that the beginning date and time is in call A2, the formula below returns the following results, provided you've applied an appropriate time format to column B, h:mm in this example:

=NOW()-A2 Calculating elapsed time from a start time to now

In case the elapsed time exceeds 24 hours, use one of these time formats, for example d "days" h:mm:ss like in the following screenshot: Calculating elapsed time over 24 hours

If your starting points contain only time values without dates, you need to use the TIME function to calculate the elapsed time correctly. For example, the following formula returns the time elapsed since the time value in cell A2 up to now:

=TIME(HOUR(NOW()), MINUTE(NOW()), SECOND(NOW())) - A2 Calculating elapsed time without dates

Note. The elapsed time is not updated in real-time, it refreshes only when the workbook is reopened or recalculated. To force the formula to update, press either Shift + F9 to recalculate the active spreadsheet or hit F9 to recalculate all open workbooks.

Formula 5. Display time difference as "XX days, XX hours, XX minutes and XX seconds"

This is probably the most user-friendly formula to calculate time difference in Excel. You use the HOUR, MINUTE and SECOND functions to return corresponding time units and the INT function to compute the difference in days. And then, you concatenate all these functions in a single formula along with the text labels:

=INT(B2-A2) & " days, " & HOUR(B2-A2) & " hours, " & MINUTE(B2-A2) & " minutes and " & SECOND(B2-A2) & " seconds" A user-friendly Excel time difference formula

To instruct your Excel time difference formula to hide zero values, embed four IF functions into it:

=IF(INT(B2-A2)>0, INT(B2-A2) & " days, ","") & IF(HOUR(B2-A2)>0, HOUR(B2-A2) & " hours, ","") & IF(MINUTE(B2-A2)>0, MINUTE(B2-A2) & " minutes and ","") & IF(SECOND(B2-A2)>0, SECOND(B2-A2) & " seconds","")

The syntax may seem excessively complicated, but it works :) Excel time difference formula that ignores zero values

Alternatively, you can calculate time difference by simply subtracting the start time from the end time (e.g. =B2-A2), and then apply the following time format to the cell:

d "days," h "hours," m "minutes and" s "seconds" Subtract the start time from the end time and apply the custom time format to the cell.

An advantage of this approach is that your result would be a normal time value that you could use in other time calculations, while the result of the complex formula discussed above is a text value. A drawback is that the custom time format cannot distinguish between zero and non-zero values and ignore the latter. To display the result in other formats, please see How to show time over 24 hours, 60 minutes, 60 seconds.

How to calculate and display negative times in Excel

When calculating the time difference in Excel, you may sometimes get the result as ###### error because the difference is a negative time. But is there a way to show negative times properly in Excel? Of course, there is a way, and even more than one :)

Method 1. Change Excel Date System to 1904 date system

The fastest and easiest way to display negative time normally (with a minus sign) is switching to the 1904 date system. To do this, click File > Options > Advanced, scroll down to the When calculating this workbook section and put a tick in the Use 1904 date system box. Changing to the 1904 data system

Click OK to save the new settings, and from now on negative times will be displayed correctly, like negative numbers: In the 1904 date system, negative times are displayed like negative numbers

Method 2. Calculate negative time in Excel with formulas

Is changing Excel's default Date System is not an option, then you can force negative times to display properly using one of the following formulas:

=IF(A2-B2>0, A2-B2, "-" & TEXT(ABS(A2-B2),"h:mm"))

=IF(A2-B2>0, A2-B2, TEXT(ABS(A2-B2),"-h:mm"))

Both formulas check if the time difference (A2-B2) is greater than 0, and if it is they return that difference. If the time difference is less than zero, the first formula calculates the absolute difference and concatenates the minus sign. The second formula yields exactly the same result by using a negative time format "-h::mm". A formula to calculate negative times in Excel

Note. Please keep in mind that unlike the first method that treats negative times as negative numeric values, the result of the TEXT function is always a text string that cannot be used in calculations or other formulas.

Adding and subtracting time in Excel

Basically, there are 2 ways to add and subtract time in Excel:

  • Using the TIME function
  • Using arithmetic calculations based on the number of hours (24), minutes (1440) and seconds (86400) in one day

The TIME(hour, minute, second) function makes Excel time calculations really easy, however it does not allow adding or subtracting more than 23 hours, or 59 minutes, or 59 seconds. If you are working with bigger time intervals, then use one of the arithmetic calculations demonstrated below.

How to add or subtract hours to time in Excel

To add hours to a given time in Excel, you can use one the following formulas.

TIME function to add under 24 hours

=Start time + TIME(N hours, 0, 0)

For example, if your start time is in cell A2, and you want to add 2 hours to it, the formula is as follows:

=A2 + TIME(2, 0, 0) TIME function to add under 24 hours

Note. If you try adding more than 23 hours with the TIME function, the specified hours will be divided by 24 and the remainder will be added to the start time value. For example, if you try to add 25 hours to "6/2/2015 10:00 AM" (cell A4) using the formula =A4 + TIME(25, 0, 0), the result will be "06/02/2015 11:00", i.e. A4 + 1 hour.

Formula to add any number of hours (under or over 24 hours)

The following formula has no limitations to the number of hours you want to add:

= Start time + (N hours / 24)

For example, to add 28 hours to the start time in cell A2, enter the following formula:

=A2 + (28/24) Universal formula to add hours to a given time in Excel

To subtract hours from a given time, you use analogous formulas, and just replace "+" with the minus sign:

For example, to subtract 3 hours from the time in cell A2, either of the following formulas will do:

=A2-(3/24)

=A2-TIME(3,0,0)

To subtract more than 23 hours, use the first one.

How to add / subtract minutes to time in Excel

To add minutes to a given time, employ the same techniques that we've just used for adding hours.

To add or subtract under 60 minutes

Use the TIME function and supply the minutes you want to add or subtract in the second argument:

=Start time + TIME(0, N minutes, 0)

And here are a couple of real-life formulas to calculate minutes in Excel:

To add 20 minutes to the time in A2: =A2 + TIME(0,20,0)

To subtract 30 minutes from the time in A2: =A2 - TIME(0,30,0)

To add or subtract over 60 minutes

In your calculation, divide the number of minutes by 1440, which is the number of minutes in a day, and add the quotient to the start time:

=Start time + (N minutes / 1440)

To subtract minutes from time, simply replace plus with the minus sign. For example:

To add 200 minutes: =A2 + (200/1440)

To subtract 300 minutes: =A2 -(300/1440) Adding and subtracting minutes in Excel

How to add / subtract seconds to a given time

Second calculations in Excel are done in a similar fashion.

To add under 60 seconds to a given time, you can use the TIME function:

=Start time + TIME(0, 0, N seconds)

To add more than 59 seconds, use the following formula:

=Start time + (N seconds / 86400)

To subtract seconds, utilize the same formulas with the minus sign (-) instead of plus (+).

In your Excel worksheets, the formulas may look similar to these:

To add 30 seconds to A2: =A2 + TIME(0,0,31)

To add 1200 seconds to A2: =A2 + (1200/86400)

To subtract 40 seconds from A2: =A2 - TIME(0,0,40)

To subtract 900 seconds from A2: =A2 - (900/86400)

How to sum time in Excel

The Excel sum time formula is the usual SUM function, and applying the proper time format to the result is what does the trick.

Supposing you have a few project times in column B and you want to add them up. You write a simple SUM formula like the one below and get the result in the default format such as hh:mm:ss.

=SUM(B2:B4) A SUM formula to add up times in Excel

In some cases the default time format works just fine, but sometimes you may want more, for example to display the total time as minutes and seconds, or seconds only. The good news is that no other calculations are required, all you have to do is apply custom time format to the cell with the SUM formula.

Right click the cell and select Format Cells in the context menu, or press Ctrl + 1 to open the Format Cells dialog box. Select Custom from the Category list and type one of the following time formats in the Type box:

  • To display total time as minutes and seconds: [m]:ss
  • To display total time as seconds: [ss]

The result will look as follows: Apply the custom time format to display total time as minutes and seconds, or seconds only.

How to sum over 24 hours in Excel

In order to add up more than 24 hours, you use the same SUM formula as discussed above, and apply one of the following time formats to the cell:

Format Displays as Explanation
[h]:mm 30:10 Hours and minutes
[h]:mm:ss 30:10:20 Hours, minutes and seconds
[h] "hours", mm "minutes", ss "seconds" 30 hours, 10 minutes, 20 seconds
d h:mm:ss 1 06:10:20 Days, hours, minutes and seconds
d "day" h:mm:ss 1 day 06:10:20
d "day," h "hours," m "minutes and" s "seconds" 1 day, 6 hours, 10 minutes and 20 seconds

To see how these custom time formats may look like in your Excel worksheet, please have a look at the screenshot below, where the same SUM formula is entered in cells A9 to A13:

=SUM($B$2:$B$4) Adding up more than 24 hours in Excel

Note. The above custom time formats work for positive values only. If the result of your time calculations is a negative number, e.g. when you are subtracting a bigger time from a smaller time, the result will be displayed as #####. To display negative times differently, please see custom format for negative time values.

Also, please keep in mind that the time format applied to a cell changes only the display presentation without changing the cell's value. For example, in the screenshot above, cell A13 looks like text, but in fact it's a usual time value, which is stored as a decimal in the internal Excel system. Meaning, you are free to refer to that cell in other formulas and calculations.

For more information, please see How to calculate and show over 24 hours, 60 minutes, 60 seconds.

Date & Time Formula Wizard - quick way to calculate times in Excel

Now that you know a bunch of different formulas to add and subtract times in Excel, let me show you the tool that can do it all. Okay, almost all :)

Here comes Ablebit's Date & Time Formula Wizard for Excel: Date & Time Formula Wizard for Excel

In the Date & Time Wizard dialog window, you switch to the Add or Subtract tab, depending on which operation you want to perform, and do the following:

  • Click the Show time fields link in the left part of the window.
  • Supply values or cell references for the formula arguments. As you fill in the argument boxes, the wizard builds the formula in the selected cell.
  • When finished, click the Insert Formula

That's it! For example, this is how you can add the specified number of hours, minutes and seconds to the time in A4: Add hours, minutes and seconds to the original time in Excel

If you need to copy the formula to other cells, fix all references except the cell containing the original time (A4) with the $ sign like shown in the screenshot below (by default, the wizard always uses relative references). Then double-click the fill handle to copy the formula down the column and you are good to go! Formula to add hours, minutes and seconds to time in Excel

Besides time calculations, the wizard can also add and subtract dates, get the difference between two dates, and calculate age from the birthdate.

If you are curious to try this tool in your own worksheets, you are welcome to download the evaluation version of our Ultimate Suite below.

This is how you calculate time in Excel worksheets. To learn other ways to manipulate dates and times in Excel, I encourage you to check out the resources at the end of this article. I thank you for reading and hope to see you on our blog next week!

Available downloads

Excel Time Calculations - formula examples (.xlsx file)
Ultimate Suite - trial version (.exe file)

1021 comments

  1. HI, I need help with a time formula. C1 is 13:40, C2 is 16:40 and C3 gives me the difference of 3:00. I have these formulas set up. What i am trying to do is check another cell, (C5) for "specific text" prior to returning a result of C3 as the full value (3:00) or half value (1:30) to C6.

    Thanks in advance
    Doug

  2. HI, I need help with a time formula. C1 is 13:40, C2 is 16:40 and C3 gives me the difference of 3:00. I have these formulas set up. What i am trying to do is check another cell, (C5) for "specific text" prior to returning a result of C3 as the full value (3:00) or half value (1:30) to C6.

    Thanks
    Doug

  3. =A2 + TIME(2, 0, 0)

    hello

    thanks a lot it was very good but I have a question.

    I want to add one hour to my time but I have a large data in one column, how can I write the formulation to apply it for whole of the data in the column once?

    thanks in advance

  4. I've been reading up on Excel's date and time functions and can't really figure out the best way of doing this. Any input would be appreciated.

    (Start Date/time) A1 = 11/25/2016 14:00
    (Hour to fix) B2 = 20 hours
    (Fix date/time) C1 = fix time?
    Business hour = Mon - Sun 08:00 - 20:00

    I'd like to enter a date and time into a cell (Start Date) and have another cell return the date and time that the machine should be done with the task including weekends (End Date). This would be based on a certain number of "business hours" that would be calculated in another cell.

  5. I'm Trying to Subtract the Below said wrong time format, Answer should be =30, Please help me

    A1 = 03.00PM
    A2 = 2:30 PM

  6. Hi,

    I need to calculate day wise hour wise penalty.

    In a day (24 hours) exemption hours are 20 (total 24 months).

    If down time is > 4 hours in a day, Per Hour Rs.200/- penalty.

    Pls share formula..

  7. Best explanation I have ever seen... Many thanks to Svetlana Cheusheva.

  8. I am trying to calculate total hours worked in a day with the result being in number instead of time. For Example 8.5 instead of 8:30. Using clock in(C27), lunch out(G27), lunch in(H27), clock out(L27) to calculate total hours. I am using =(L27-H27)+(G27-C27). I also have the cell with the results formatted as (Custom [h]:mm). What can I add to the formula or how should I format the cell to change the results to my liking?

  9. i am calculating day and month difference in twodays
    cell a1 07/07/2016
    cell b1 07/10/2016
    formula =TEXT(B1-A1,"m") it displaying 4 but the difference in month is 3

    =TEXT(B1-A1,"dd") its displaying 1 but the difference in days should b 0

    plz revert

    and plz let me know also can v calculate years in two dates

  10. does anyone have a template?

  11. I would appreciate help with formulas for the following:
    Sign in time: 9:35am
    Minus max duty day: 18 hours
    Minus debrief: 30 minutes
    Minus flying time: 14 hours, 20 minutes
    What I need is the final time after the above calculations.

    Thank you!

  12. I would like to calculate end time.
    I have Start time and number of hours but looking to calculate end time. Example: Start time 5 am, 9 hours, can you help me calculate end time in excel? I have 350 entries.

  13. Hiii.,
    I need a formula for creating a sheet in excel for notification means today is 25th Oct 2016, so i need from 25th to every 29days have to remind in excel and auto deduct amount on 29th day of every month.

  14. Many of the help requests posted here exhibit a basic misunderstanding about how Excel looks at time. When we see hh:mm we may be thinking "duration", and 29 hours 57 minutes makes perfect sense to us. When Excel sees hh:mm it always thinks "clock", and I've never seen a clock with 29 hours marked on the face.

    On a blank Excel spreadsheet, pick an empty cell formatted as "General" (default). Enter "hello" in that cell. Note that the format didn't change.

    Now replace "hello" with "7:30". Did the format of the cell change to "Custom (h:mm)"? Look at the Formula Bar. Does it say "7:30:00 AM"? That's a clock reading. We may have meant 7 and a half hours, but Excel understood it as 7:30 AM.

    Now enter two durations, 14:27 and 19:42, in cells A1 and A2. In A3, sum A1 and A2.

    We expect a sum of 34:09, but we get 10:09 instead. Why? Excel is adding clock times, and there's only 24 hours on the clock. So Excel's answer is 1 day, 10 hours and 9 minutes. But cell A4 doesn't automagically format as d:hh:mm. It formats as h:mm, so all we see is 10:09 - the hours and minutes. Now change the format on cell A3 to d:hh:mm, and it will make more sense.

    But we really wanted the result in just hours and minutes, not days. Enter this into cell A4 to convert the total to hours and minutes:
    =DAY(A3)*24+HOUR(A3)&":"&TEXT(MINUTE(A3),"00")

    Note that cell A4 is formatted as General. That isn't an Excel date/time format, so we can't perform math functions on/with it.

    Excel dates are basically integers - one for every day starting with 1/1/1900. For example, 6/6/2016 is day number 42,527.

    Excel times are decimal numbers representing a portion of a day, and there are 86,400 seconds in a full day. 11:53:15 equates to
    11 hours x 60 minutes x 60 seconds
    + 53 minutes x 60 seconds
    + 15 seconds,
    or a total of 42,795 seconds. Dividing that by 86,400 seconds, we see that 11:53:15 converts to 0.4953125 days.

    So Excel represents 6/6/16 11:53:15 AM as 42527.4953125.

    Because dates and times are just numbers to Excel, they can easily be added and subtracted. The results can be formatted simply as numbers, or in a goodly number of standard date/time formats.

    If the result of your date/time manipulations don't look right, check the cell format - there may be more data there than meets the eye.

    And if you want the results of date/time manipulations to be formatted in some way other than the standard Excel date/time formats, do all the math first using standard formats - then convert the results to the format you require.

  15. That did the trick. Thank you!!!

  16. I need to add seconds with the final result of minutes and seconds i.e. 30+30+15+5 which sums to 1 minute and 20 seconds and should display as 1:20. Anyone have any idea of a formula that will work?

    • Enter your seconds in col A as numbers.
      =SUM(A:A)/(86400) {formatted as "m:ss"}

  17. I'm trying to create a time sheet to calculate the hours for the employee where I need to round up In time and out time by quarters and deduct lunch break. For example

    In time Break In Out Out time
    08:09 = 8:15 13:00 13:50 17:38 = 17:45 Total???

    How can I formulate the last column into calculate the total hours worked?

    Thank you!

    • Viktoria,
      Per the rules as stated (starttime 8:00 = 8:00, starttime 8:01=8:15; similar for stoptime; breaktimes not adjusted to quarter-hours), this should work for the Total column (E):
      =(HOUR(D1)+CEILING(MINUTE(D1)/15,1)/4)/24-(HOUR(A1)+CEILING(MINUTE(A1)/15,1)/4)/24+B1-C1

  18. I answer phones virtually and I am trying to calculate the total # of mm:ss.
    Each call I take has a total talk time. So like I took 6 calls.
    4:23 4:23
    1:45 6:08
    2:24 8:32
    2:00 10:32
    5:36 16:08
    10:52 3:00 (This should be 27:00). But anything over 24:00 won't calculate correctly. So how do I fix this?

    • You think you're entering minutes:seconds, but you're actually entering hours:minutes, which is why anything over 24 minutes goes haywire.
      Format the columns as "mm:ss", but enter the data as h:m:ss - in other words enter 0:5:36 instead of 5:36. Then just subtract col A from col B.
      02:00 10:32 08:32

  19. i need over time formula
    eg.
    a2 09:00 b2 18:00 (c2 ans =a2-b2 we get 09:00)

    but we need over time after this result we want -08:00 hour working day
    if i do b2-a2-08:00=######

    what is the perfect formula for over time result will you help me please

    • =B2-A2-8/24
      (subtract 8/24 of a day rather than 8 hours)

  20. i want formula for
    3:15 pm to 12:15 am

    if 12:15 am - 3:15 pm = ######
    what is correct formula for it how it is come
    12:15 am - 3:15 pm = 9:00

Post a comment



Thank you for your comment!
When posting a question, please be very clear and concise. This will help us provide a quick and relevant solution to
your query. We cannot guarantee that we will answer every question, but we'll do our best :)