Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. 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.
Written by Allen Wyatt (last updated May 14, 2022)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021
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:
Figure 1. The Format Cells dialog box.
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, 2016, 2019, Excel in Microsoft 365, and 2021. You can find a version of this tip for the older menu interface of Excel here: Working with Elapsed Time.
Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!
Need to check the current time in a formula you are putting together? It can sometimes be tricky to remember what Excel ...
Discover MoreYou know what time it is, right? (Quick; look at your watch!) What if you want to know what time it is in Greenwich, ...
Discover MoreWhen you enter a time value into Excel, the program tries its hardest to make the value into a valid time. This can lead ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2022-05-14 09:57:07
J. Woolley
My Excel Toolbox includes the following function:
=TimeDif(Start,Finish,[Approximate],[Conversational])
This returns the difference between two time values or two date values (with or without time-of-day) as text. If Start > Finish, they will be exchanged so their difference is a positive value.
For example:
=TimeDif(TODAY(),NOW())
returns "00 yr 00 mth 00 day 09 hr 52 min 37 sec"
=TimeDif(TODAY(),NOW(),TRUE)
returns "almost 10 hours"
=TimeDif(TODAY(),NOW(),,TRUE)
returns "9 hours and 52 minutes"
See https://sites.google.com/view/MyExcelToolbox/
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments