Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Office 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

by Allen Wyatt
(last updated December 8, 2018)

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 Office 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

Adjusting the VLOOKUP Function

The VLOOKUP function is very powerful, but it will only return values that meet a very limited set of criteria. If you ...

Discover More

Numbering on New Paragraph Doesn't Work as Expected

The Numbering feature in Word can be a bit tricky to navigate. Sometimes it works as it should, and other times it seems ...

Discover More

Using RD Fields with Chapter Headings

The RD field can be handy for pulling together a bunch of documents into a single file. However, using the field can play ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More ExcelTips (ribbon)

Copying Dates a Year Into the Future

Need to copy a range of dates and update them to a different year? Here are a number of ways to accomplish this task with ...

Discover More

Counting Month Ends

When working with dates in a worksheet, you may need to do some rather esoteric calculations on those dates. This tip ...

Discover More

Converting Coded Dates into Real Dates

Sometimes the format in which you receive data is not the same format that would be optimal for Excel. For instance, you ...

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}] 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 3?

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.