To calculate the number of years between two dates in Excel, use the DATEDIF function with the "Y" unit, which returns the complete years between a start and end date. Ensure both dates are valid Excel date serial numbers (not text) and entered in standard date format (e.g., 1/1/2020). No add-ins or special tools are required—only Excel’s built-in functions.
What You'll Need
- Microsoft Excel (any modern version: Excel 2010, 2013, 2016, 2019, 2021, or Microsoft 365)
- Two valid dates entered in separate cells (e.g., A2 and B2)
- Basic familiarity with Excel cell references and formula entry
Step-by-Step
- Open your Excel workbook and locate or enter your two dates. For example, type the earlier date in cell A2 (e.g.,
1/1/2015) and the later date in cell B2 (e.g.,6/15/2024). Ensure Excel recognizes these as actual dates—not text—by checking that numbers appear right-aligned in the cell. If they’re left-aligned or show as#VALUE!, format them as dates: select the cells, go to the Home tab > Number group > choose Short Date from the dropdown. - Click on the cell where you want the year difference to appear (e.g., C2).
- Enter the DATEDIF formula:
=DATEDIF(A2, B2, "Y"). This calculates full calendar years elapsed between the start date (A2) and end date (B2). Press Enter. - Verify the result. For 1/1/2015 to 6/15/2024, Excel returns 9 because only nine full years have passed (2015→2016, ..., 2023→2024 is incomplete as of June).
- To calculate years for multiple rows, drag the fill handle (small square at the bottom-right of the selected cell) down to copy the formula to other rows. Excel automatically adjusts cell references (e.g., A3/B3, A4/B4).
- Optional: For more context, add a text label. In cell D2, enter
=C2 & " year(s) between " & TEXT(A2,"mm/dd/yyyy") & " and " & TEXT(B2,"mm/dd/yyyy")to produce a readable sentence like 9 year(s) between 01/01/2015 and 06/15/2024.
Common Mistakes
- Using text instead of dates: Typing
Jan-15or2015-01-01without proper formatting may store them as text, causing #VALUE! errors. Always convert to Excel date serials first. - Swapping start and end dates: DATEDIF requires the start date to be earlier than the end date. If B2 < A2, Excel returns #NUM! error. Use
=IF(B2to validate first. - Missing quotes around "Y": Writing
=DATEDIF(A2,B2,Y)without quotes treatsYas an undefined name, resulting in #NAME? error. Always include the unit in double quotes:"Y". - Expecting partial years: DATEDIF only counts complete years. For a period like 1/1/2020 to 12/31/2020, it returns 0—not 1—even though 12 months passed. Use "M" or "D" units for months/days if needed.
- Ignoring leap years or month length differences: DATEDIF handles this internally, but users sometimes miscount manually. Trust the function: 2/28/2020 to 2/28/2021 returns 1, while 2/28/2021 to 2/28/2022 returns 1 (despite 2021 not being a leap year).
Tips
- Combine with TODAY(): To find someone’s age as of today, use
=DATEDIF(A2, TODAY(), "Y")where A2 holds their birthdate. The result updates automatically each day. - Use INT for rounding: For approximate years including fractions (e.g., 9.4 years), use
=INT((B2-A2)/365)or=ROUNDDOWN((B2-A2)/365,0)—though less precise for leap years than DATEDIF. - Handle blank cells: Wrap DATEDIF in IFERROR to avoid errors from missing data:
=IFERROR(DATEDIF(A2,B2,"Y"),"")returns blank if either date is missing. - Format output cells: Select result cells, press Ctrl+1, choose Number tab, and set Decimal places to 0 to remove trailing decimals (though DATEDIF always returns integers).
- Test edge cases: Try dates like 2/29/2020 (leap day) to 2/28/2021—DATEDIF treats this as 0 years since Feb 29 never occurs in 2021. Use
=DATEDIF(A2, DATE(YEAR(B2),MONTH(B2),DAY(B2)),"Y")for consistency.
Troubleshooting
If your formula doesn’t work, follow these steps in order:
- Check for #VALUE!: This means one or both dates aren’t valid. Use
=ISNUMBER(A2)and=ISNUMBER(B2)to confirm. If FALSE, re-enter the dates using Excel’s date picker (Insert > Date & Time > Date) or type1/1/2020directly. - Fix #NUM!: This occurs when the start date is later than the end date. Swap the references:
=DATEDIF(MIN(A2,B2), MAX(A2,B2), "Y")ensures correct order. - Resolve #NAME?: Excel doesn’t recognize DATEDIF if the function name is misspelled or the Analysis ToolPak add-in is missing (in older Excel versions). First, double-check spelling. If using Excel for Mac or newer Microsoft 365, DATEDIF is built-in and doesn’t require add-ins. If still failing, try
=YEAR(B2)-YEAR(A2)as a fallback—though it ignores month/day (e.g., 12/31/2020 to 1/1/2021 returns 1, not 0). - Date format issues: Press Ctrl+1 > Number tab > select Custom and enter
mm/dd/yyyyto standardize display. If dates appear as#####, widen the column by dragging the header boundary. - Formula not updating: Ensure calculation is set to Automatic: go to Formulas tab > Calculation Options > select Automatic. If manual, press F9 to recalculate.
Frequently Asked Questions
Does DATEDIF count the start date or end date?
No—it counts complete years *between* the dates. For example, from 1/1/2020 to 1/1/2021 is exactly one year, so DATEDIF returns 1. The start date is included in the period, but only full calendar-year transitions count.
Can I get decimal years (e.g., 9.5 years)?
DATEDIF only returns whole numbers. For decimals, use =(B2-A2)/365.25 to approximate (accounting for leap years), or =DAYS(B2,A2)/365 in newer Excel versions. Note: These are approximations and may be off by ~0.25 days per year.
What if my dates include time (hours/minutes)?
Excel stores dates as serial numbers with decimals for time (e.g., 1/1/2020 6:00 PM = 43831.75). DATEDIF ignores time and only compares the date portion. To be safe, wrap dates with INT() to truncate time: =DATEDIF(INT(A2), INT(B2), "Y").
How do I calculate years between today and a past date?
Use =DATEDIF(start_date, TODAY(), "Y"). Example: If A2 is 5/20/2010, =DATEDIF(A2, TODAY(), "Y") gives current age or elapsed years. This updates daily without manual changes.
Why does 12/31/2019 to 1/1/2020 return 0?
Because only one day passed—no full calendar year elapsed. DATEDIF counts *completed* years. From Dec 31 to Jan 1 spans less than 365 days, so it returns 0. Use "D" to confirm: =DATEDIF("12/31/2019","1/1/2020","D") = 1.
Does this work in Excel Online or mobile apps?
Yes—DATEDIF is supported in Excel Online, Excel for Android/iOS, and Excel for Mac. Function behavior is identical across platforms, but ensure your device’s regional settings don’t alter date parsing (e.g., DD/MM/YYYY vs MM/DD/YYYY). Use consistent date formats to avoid errors.