Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, and 2016. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Working with Elapsed Time.

Working with Elapsed Time

by Allen Wyatt
(last updated January 23, 2016)

4

Excel allows you to enter many things into a cell, including times. This leads some people to use Excel to help calculate elapsed times. For instance, you may have a column that contains a starting time, another that contains an ending time, and then use a third column to calculate the time between the beginning and ending time.

In such situations, you may be tempted to simply put the following as your formula in the cells of the third column:

=B2-A2

This will work fine, provided the time shown in B2 is always later than the time shown in A2. However, you will get erroneous results if the times do not fit this rigid stricture. What do you do if you are running operations around the clock, and it is just as likely that the value at A2 will be just before midnight and the value in B2 will be after midnight?

One solution is to make sure that you always enter dates with your times. If you do this, then B2 will always be later than A2. For many people, however, this is a bother. If you find yourself simply entering the time, then you are still up the creek.

If you enter your times without an AM/PM designation using a 12-hour clock, then you should use the following formula in the cells of the third column:

=IF(A2>B2,(B2+0.5)-A2,B2-A2)

This formula uses the IF function to determine if the beginning time is later than the ending time. If it is, then .5 (which is half a day, or 12 hours) is added to the ending time before the subtraction is done. If the beginning time is earlier then the ending time, then a normal subtraction operation is done.

If you use an AM/PM designation in your times, or you enter information using a 24-hour clock, then the formula must change just a bit. Now it should appear as follows:

=IF(A2>B2,(B2+1)-A2,B2-A2)

Now, instead of adding only half a day, you are adding a whole day (24 hours) to the ending time. This, again, provides the proper result.

It is interesting to note that in both of these instances, Excel allows you to add hours and minutes, if desired. While the above example is clean and simple, the following could also have been used:

=IF(A19>B19,(B19+"24:00")-A19,B19-A19)

Regardless of the formula you use, once it is entered you need to make sure the cell with the formula is formatted to properly show elapsed time. You do this by following these steps:

  1. Press Ctrl+1. Excel displays the Format Cells dialog box. (See Figure 1.)
  2. Figure 1. The Format Cells dialog box.

  3. In the Category list (left side) choose Time.
  4. In the Type box, choose 37:30:55 as the type.
  5. Click on OK.

Your cell now shows the correct elapsed hours, minutes, and seconds.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (11801) applies to Microsoft Excel 2007, 2010, 2013, and 2016. You can find a version of this tip for the older menu interface of Excel here: Working with Elapsed Time.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Editing the Same Cell in Multiple Sheets

When creating a workbook, you may need to make changes on one worksheet and have those edits appear on the same cells in ...

Discover More

Updating Links in Copied Files

When you copy workbooks that contain links, you may be at a loss as to how to update those links. There are a couple of ways ...

Discover More

Select All Changes by a Particular Reviewer

The Track Changes feature in Word allows you and other editors to easily collaborate on the development of a document. If you ...

Discover More

Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!

More ExcelTips (ribbon)

Checking for Time Input

Need to know if a cell contains a time value? Excel doesn't contain an intrinsic worksheet function to answer the question, ...

Discover More

Determining If a Date and Time is within Working Hours

Excel is great at working with times and dates. Sometimes, though, it can be a bit tricky to figure out how to work with both ...

Discover More

Combining and Formatting Times

Excel allows you to store times in your worksheets. If you have your times stored in one column and an AM/PM indicator in ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is one more than 9?

2016-01-25 11:46:59

Scott Renz

Richard:

Instead of selecting the Time Category, select the Custom Category. Then in the box under "Type:" which probably says "General", make the box blank and type in "h:mm:ss" without the quotes.


2016-01-25 03:48:24

Richard

Here in the UK, I find that they 37:30:55 type isn't available in the English (United Kingdom) locale.


2016-01-23 10:59:24

Jerry

Another way to adjust the elapsed time for the over-midnight situation is the formula =B2-A2+(B2<A2).
The (B2<A2) part is a logical expression, resulting in TRUE if the time in B2 is less than the time in A2. Since Excel treats TRUE as a value of 1, this adds a time value of 1 (24 hours) to the calculation. If the time in B2 is greater than A2, the logical expression is FALSE, which is zero, and no adjustment is required.


2016-01-23 07:06:28

Michael (Micky) Avidan

@To whom it may concern,
To my opinion, the easiest & shortest formula is: =MOD(B2-A2,1)
--------------------------
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2016)
ISRAEL


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.