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: Unique Date Displays.

Unique Date Displays

Written by Allen Wyatt (last updated April 20, 2024)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021


3

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, 1991 from August 12, 2019, the result would be 28.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:

  1. Select the cell. (In this case, cell C2.)
  2. Display the Home tab of the ribbon.
  3. Click the small icon at the lower-right corner of the Number group. Excel displays the Format Cells dialog box.
  4. Make sure the Number tab is selected. (See Figure 1.)
  5. Figure 1. The Number tab of the Format Cells dialog box.

  6. In the Category list, at the left side of the dialog box, choose Custom.
  7. In the Type box, at the left of the dialog box, enter the following format: yy.m
  8. Click on OK.

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. (Hence, the result of 28.8 in C2.)

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 result is 28.07 in C2.) There are two potential problems with this approach. First, it won't give the right result if the date in A2 is after the date in B2, particularly if the dates are in different years. (You'll end up with negative years that way.) The second problem is that the months are always expressed using two decimal places, and you may want to not have any leading zeroes.

Both issues can be solved by modifying your formula to use the DATEDIF function, returning the result as text instead of as a numeric value, in this manner:

=IF(A2 < B2, DATEDIF(A2,B2,"y") & "." & DATEDIF(A2,B2,"ym"), DATEDIF(B2,A2,"y") & "." & DATEDIF(B2,A2,"ym"))

There are two variations of the DATEDIF function in this formula, wrapped in an IF function. The reason is because DATEDIF expects the first parameter to be earlier than the second parameter, and the IF function checks to make sure this is the case.

The result in C2 is now 28.7, but it is a text string, not a numeric value. It is necessary to return a text string because a difference of 1 and 10 months would both return as something like 28.1 if the result were numeric.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (11057) 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: Unique Date Displays.

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

Smart Quotes with Dragon Naturally Speaking

Dragon Naturally Speaking is a very popular transcription tool that converts speech into text. When using the program ...

Discover More

Getting Help Offline

Word provides two different sources from which you can get help—either online or offline. By default, Word uses the ...

Discover More

Naming Tabs for Weeks

Need to set up a workbook that includes a worksheet for each week of the year? Here's a couple of quick macros that can ...

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

More ExcelTips (ribbon)

Calculating a Date Five Days before the First Business Day

Excel allows you to perform all sorts of calculations using dates. A good example of this is using a formula to figure ...

Discover More

Advancing Dates to a New Year

If you store dates in your worksheets, you may want to update those dates at the end of the year. This tip explains ...

Discover More

Calculating the Last Day in a Week Number

Given a particular week number for a year, you may want to figure out the date of the last day in that week. There is no ...

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}] (all 7 characters, in the sequence shown) 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 8 - 5?

2024-04-23 10:54:47

J. Woolley

Re. my earliest comment below, all 6 the formulas ending with a divisor of 10 should instead have a divisor of 100 and displayed using Number format with 2 decimal places. Obviously a month can have more than 1 digit. My bad.

Re. my most recent comment below, the first formula's result should be formatted as Number with 2 decimal places, not General. The formulas that use a custom fractional format are okay even when MONTH(B2) <= MONTH(A2), but if
B2 < A2 the result will be negative.


2024-04-22 11:31:34

J. Woolley

Re. my previous comment below, here is a simpler formula for C2 resulting in 28.07 when formatted as General:
    =TEXT(B2-A2,"yy.mm")-1/100
Jon wanted the numeric value to be 28.7, but 28.07 might be a better representation of 28 years and 7 months.

Here is a another formula
    =(B2-A2)/365.25
with the numeric result 28.59411362 displayed as
    28 + 7/12
when custom formatted as fractional
    # "+" ?/12
The following formula is more accurate (see the Tip):
    =(YEAR(B2)-YEAR(A2))+(MONTH(B2)-MONTH(A2))/12
In this case the decimal result 28.58333333 will display as
    28 + 7/12
using the custom fractional format.


2024-04-21 11:40:10

J. Woolley

If A2 is January 7, 1991, B2 is August 12, 2019, and C2 is =B2-C2 formatted as yy.m, then C2 is 28.8 rather than 28.7 as desired because m is 1 to 12 instead of 0 to 11. Here are two alternate formulas for C2 resulting in 28.7 when formatted as General:
    =LET(x, TEXT(B2-A2,"yy.mm"), y, INT(x), z, RIGHT(x,2), y+(z-1)/10)
    =LET(x, TEXT(B2-A2,"yy.mm"), INT(x)+(RIGHT(x,2)-1)/10)
The LET function requires Excel 2021+ (or 365, of course). Here is the equivalent formula for older Excel versions:
    =INT(TEXT(B2-A2,"yy.mm"))+(RIGHT(TEXT(B2-A2,"yy.mm"),2)-1)/10
Notice how text is automatically converted to numeric for arithmetic.

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, if A2 is January 7, 1991, and B2 is August 12, 2019:
    =TimeDif(A2,B2) returns "28 yr 07 mth 05 day 00 hr 00 min 00 sec"
    =TimeDif(A2,B2,TRUE) returns "about 28 and a half years"
    =TimeDif(A2,B2,,TRUE) returns "28 years 7 months and 5 days"
The first formula's result is formatted with 2 digits for each numeric value and 2 spaces after each label, but if the year result is more than 99 its numeric digits will expand appropriately. Assuming the year result does not require more than 2 digits, the following equivalent formulas will return 28.7 when formatted as General:
    =LET(x, TimeDif(A2,B2), y, MID(x,1,2), z, MID(x,8,2), y+z/10)
    =LET(x, TimeDif(A2,B2), MID(x,1,2)+MID(x,8,2)/10)
    =MID(TimeDif(A2,B2),1,2)+MID(TimeDif(A2,B2),8,2)/10
See https://sites.google.com/view/MyExcelToolbox/


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.