Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Calculate Number of Years Between Two Dates in Excel

· 4 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

To calculate the number of years between two dates in Excel, the most efficient method is using the =DATEDIF(start_date, end_date, "y") formula. This function calculates the number of complete years that have passed between the start date and the end date, ignoring any remaining months or days.

What You'll Need

  • A computer with Microsoft Excel installed (works across all modern versions, including Office 365, Excel 2021, 2019, and earlier).
  • Two valid date entries in your spreadsheet (e.g., a birth date and today's date).

Step-by-Step

  1. Enter Your Dates: Input your start date in one cell (e.g., cell A2) and your end date in another cell (e.g., cell B2). Ensure these are formatted as "Date" in the Home tab under the Number group.
  2. Select the Result Cell: Click on the empty cell where you want the total number of years to appear (e.g., cell C2).
  3. Enter the DATEDIF Formula: Type the following formula exactly as shown: =DATEDIF(A2, B2, "y").
    • A2 represents the start date (the older date).
    • B2 represents the end date (the more recent date).
    • "y" tells Excel to return the difference in complete years.
  4. Press Enter: Once you press Enter, Excel will display the total number of full years between the two dates.
  5. Apply to Other Rows: If you have a list of dates, click the small green square (fill handle) at the bottom-right corner of the result cell and drag it down to apply the formula to the rest of your data.

Common Mistakes

  • Reversing Date Order: If you put the end date first and the start date second (e.g., =DATEDIF(B2, A2, "y")), Excel will return a #NUM! error. The start date must always be the earlier of the two.
  • Incorrect Unit Code: Using "Y" instead of "y" generally works, but omitting the quotation marks (e.g., =DATEDIF(A2, B2, y)) will result in a #NAME? error because Excel thinks "y" is a named range rather than a text argument.
  • Using Simple Subtraction: Subtracting two dates (=B2-A2) gives you the number of days, not years. Dividing that result by 365 is often inaccurate because it does not account for leap years.

Tips

  • Dynamic End Dates: If you want to calculate age or tenure based on today's date, replace the end date cell with the TODAY() function. For example: =DATEDIF(A2, TODAY(), "y"). This ensures the calculation updates automatically every time you open the file.
  • Calculating Precise Decimals: If you need the number of years as a decimal (e.g., 10.5 years) rather than a whole number, use the YEARFRAC function: =YEARFRAC(A2, B2).
  • Combining Years and Months: To show a result like "10 Years, 3 Months," you can combine two DATEDIF functions using the ampersand symbol: =DATEDIF(A2, B2, "y") & " Years, " & DATEDIF(A2, B2, "ym") & " Months".

Troubleshooting

If the formula does not go to plan, try these steps in order:

  • Check Date Formatting: If you see a #VALUE! error, your dates might be stored as text. Select the cells, go to the Home tab, and change the format dropdown from "General" or "Text" to "Short Date." If the date doesn't change alignment, you may need to re-type it.
  • Verify the Start Date: Ensure the date in the first argument of the formula is chronologically before the date in the second argument.
  • Check for Hidden Spaces: If your dates were imported from another software, there may be hidden spaces. Use the =TRIM() function to clean the cells.
  • Check Formula Syntax: Ensure there is a comma separating each argument and that the "y" is enclosed in double quotation marks.

Frequently Asked Questions

Why is DATEDIF not listed in the Excel function menu?

DATEDIF is a "compatibility function" kept for users migrating from older versions of Lotus 1-2-3. While it works perfectly in all versions of Excel, it is not listed in the formula autocomplete menu; you must type it manually.

Does DATEDIF account for leap years?

Yes, DATEDIF correctly handles leap years when calculating the number of full years between two dates.

Can I calculate the number of years between two dates in Google Sheets?

Yes, the =DATEDIF() function uses the exact same syntax and arguments in Google Sheets as it does in Microsoft Excel.

What is the difference between "y" and "ym" in the formula?

The "y" argument calculates the total number of full years. The "ym" argument calculates the number of months remaining after the full years have been subtracted (ignoring the year component).

How do I round the result up to the next year?

DATEDIF always rounds down (truncates) to the nearest whole year. If you want to round up, use the YEARFRAC function combined with ROUNDUP: =ROUNDUP(YEARFRAC(A2, B2), 0).