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

Changing the Default File Name

When you first save a new file, Word bases the name of that file on the contents of the start of the first paragraph in ...

Discover More

Last Paragraph Line Strung Out Incorrectly

Justifying a paragraph may have undesired effects on the last line of a paragraph. If this occurs with your text, you'll ...

Discover More

Creating Many Index Entries at Once

Word makes it fairly easy to create an index. It is creating the index entries that can be tedious, especially 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)

Calculating Fractions of Years

When working with dates and the relationship between dates, Excel provides a variety of worksheet functions that may ...

Discover More

Determining If a Date is between Other Dates

Need to figure out if one date is between two other dates? There are a wide variety of formulaic approaches you could use ...

Discover More

Converting an Unsupported Date Format

Excel makes it easy to import information created in other programs. Converting the imported data into something you can ...

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 two more than 7?

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.