Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. 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 December 8, 2018)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


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.)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)))

The result in C2 is now 28.7.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (11057) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. 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

Searching for Wildcards

Wildcard characters can be used within the Find and Replace tool, but what if you want to actually search for those ...

Discover More

Showing Filter Criteria on a Printout

When you print out a filtered worksheet, you may want some sort of printed record as to what filtering was applied to the ...

Discover More

Counting Fields in a Document

Need to count the number of times a particular field appears in a document? It's easy to do when you apply the techniques ...

Discover More

Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!

More ExcelTips (ribbon)

Calculating the First Tuesday

Do you need to figure out the date for the first Tuesday of any given month? Excel is incredibly flexible when it comes ...

Discover More

Calculating Fractions of Years

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

Discover More

ISO Week Numbers in Excel

Work in an industry that uses ISO standards when it comes to working with dates? You'll love the formula in this tip ...

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 - 2?

2019-05-08 14:42:30

Dennis Costello

Another problem with =VALUE(ABS(YEAR(B2)-YEAR(A2)) & "." & ABS(MONTH(B2)-MONTH(A2))) - it gives the wrong answer when B2 is earlier in the year than A2. For instance, if A2 contains 9/13/2018 and B2 5/8/2019, there are 8 months and no full years between those two dates. The simple "B2-A2" approach shows this properly as "00.8", but the formula gives 1.4.

=VALUE(YEAR(B2) - YEAR(A2) - (MONTH(A2) > MONTH(B2)) & "." & MONTH(B2) - MONTH(A2) + (MONTH(A2) > MONTH(B2)) * 12)

This only gives sensible answers when B2 is later than A2, but that is consistent with the original problem statement. Clearly one could build a formula around =IF(MONTH(A2) > MONTH(B2), ..., ...) but I like to use the fact that TRUE becomes 1 and FALSE becomes 0.

Interestingly, the B2-A2 approach yields 00.2 when the dates are for instance 1-Apr and 31-May of the same year (i.e., it rounds the interval to the closest number of months) but the other formulas yield 0.1 (because May is only 1 month later than April).


2018-12-11 20:01:17

Peter Atherton

The DAteDif function has been done somwhere else on this site. But here is a solution using it.

=DATEDIF(A1,B1,"y")+(DATEDIF(A1,B1,"ym")*0.01)


2018-12-10 18:37:07

Yvan Loranger

Problem with =VALUE(ABS(YEAR(B2)-YEAR(A2)) & "." & ABS(MONTH(B2)-MONTH(A2))) is that diffs of 1 & 10 months would both appear as .1 (:


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.