Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Unique Date Displays.
Written by Allen Wyatt (last updated August 29, 2020)
This tip applies to Excel 97, 2000, 2002, and 2003
Jon requested help on how to subtract two dates and display the result such that the years were on the left of the decimal and the months on the right. Thus, if you subtracted January 7, 1985 from August 12, 2009, the result would be 24.7.
The easiest way to do this is to simply do your date subtractions as regular, and then use a custom format to display the result. For instance, if the lower date were in cell A2 and the higher date in B2, you could use the following formula in C2:
=B2-A2
You would then follow these steps to format the display of the result in cell C2:
Figure 1. The Number tab of the Format Cells dialog box.
The result is that C2 shows the number of years to the left of the decimal and the number of months to the right. The problem with this is that it will always vary the number of months from 1 to 12, rather than 0 to 11, as one would expect if you were looking for elapsed months.
To overcome this, you could enter the following formula in cell C2:
=(YEAR(B2)-YEAR(A2))+(MONTH(B2)-MONTH(A2))/100
This formula returns the number of years on the left of the decimal and the number of months on the right. The months are always expressed using two decimal places, however. If you wanted to make sure that the months were expressed with no leading zeros, then you would use this formula variation:
=VALUE(ABS(YEAR(B2)-YEAR(A2)) & "." & ABS(MONTH(B2)-MONTH(A2)))
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2182) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Unique Date Displays.
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!
Want to find out how many of a particular weekday occur within a given month? Here's how you can find the desired ...
Discover MoreThere are calendar days and then there are business days. Excel provides the NETWORKDAYS function that is helpful to ...
Discover MoreDon't want to use the EOMONTH function to figure out the end of a given month? Here are some other ideas for discovering ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)
Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon 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