Sub topic 10
Measuring elapsed years and months
Prerequisites and the right question
Assume you can enter formulas, use cell references, and recognize a real date value. A date value is a number that Google Sheets can calculate with, not text that only looks like a date.
Elapsed time can mean different things:
- Complete years: How many birthdays have passed?
- Complete months: How many whole billing periods have passed?
- Fractional years: How many years have passed, including part of a year?
Use DATEDIF for complete units. Use YEARFRAC when you need a decimal number of years.
Count complete years and months with DATEDIF
The syntax is:
=DATEDIF(start_date, end_date, unit)For example, if A2 contains 2018-11-28 and B2 contains 2026-11-27, this formula returns 7:
=DATEDIF(A2, B2, "Y")The "Y" unit counts complete years. The result is 7 because the eighth anniversary has not arrived yet.
Common units include:
| Unit | Meaning |
|---|---|
| `"Y"` | Complete years |
| `"M"` | Complete months |
| `"D"` | Complete days |
| `"YM"` | Remaining months after complete years |
| `"MD"` | Remaining days after complete months |
| `"YD"` | Remaining days after complete years |
To display an age as years and remaining months, use two calculations:
=DATEDIF(A2, TODAY(), "Y") & " years, " &
DATEDIF(A2, TODAY(), "YM") & " months"TODAY() returns the current date. Because it changes as the day changes, the displayed age updates automatically.
For a subscription that began in A2, complete billing months can be calculated with:
=DATEDIF(A2, TODAY(), "M")DATEDIF requires the end date to be on or after the start date. If the dates are reversed, Sheets returns an error.
Calculate fractional years with YEARFRAC
YEARFRAC returns the elapsed time as a decimal:
=YEARFRAC(A2, B2)The optional third argument selects the day-count convention. The default is 0, which uses a 30-day month and 360-day year convention. For calendar-accurate elapsed time, use basis 1:
=YEARFRAC(A2, B2, 1)The result might be approximately 7.997, depending on the dates and leap years. Round it only for presentation:
=ROUND(YEARFRAC(A2, B2, 1), 2)Do not use a fractional result as an age unless that is what your application requires. For example, legal or customer-facing ages usually need complete years from DATEDIF.
Understand anniversary edge cases
Month and year boundaries cause most mistakes. A person born on February 29 has no February 29 in most years. DATEDIF still compares complete calendar years, but your business rule may need a special policy for non-leap years.
This flow shows the choice between complete and fractional measurements:
Always verify whether the start date is inclusive, whether the end date is inclusive, and how leap days should be handled. Those rules matter more than the formula alone.
Exercise
A2 contains 2020-06-15 and B2 contains 2023-04-14. Which formula returns complete years, and what result should it produce?
Show answer
Use =DATEDIF(A2, B2, "Y"). It returns 2 because the third anniversary has not arrived.