Instant digital downloadExcel and Google SheetsSecure card checkout

Excel and Google Sheets how-to

Calculate years of service from a start date

Ana started on 15 March 2019. How many full years has she worked? DATEDIF counts them, and the same formula works out an age from a date of birth.

ABCDE
1NameStart dateYearsAs of
2Ana2019-03-1572026-10-20
3Raj2021-11-014
4Kim2024-06-302
5Lee2010-01-0416
6Sam2026-02-090

Sample data. Start dates in B, the date to count up to in E2, the formula in C2 is copied down.

The formula

Put the date you count up to in one cell (E2 here, 20 Oct 2026), click the first Years cell and type:

=DATEDIF(B2,$E$2,"Y")

C2 shows 7: Ana started on 15 Mar 2019, so she has 7 complete years by 20 Oct 2026. Copy it down and Raj shows 4, Kim 2, Lee 16 and Sam 0.

  • B2 is the start date.
  • $E$2 is the end date. The dollar signs keep it on E2 when you copy the formula down.
  • "Y" asks for complete years. A year only counts once the anniversary has passed, so Raj (started 1 Nov 2021) still shows 4 until 1 Nov 2026.

Count up to today

Use TODAY() as the end date and the years go up by themselves on each anniversary:

=DATEDIF(B2,TODAY(),"Y")

On 20 Oct 2026 it gives 7 for Ana, the same as above. Put a date of birth in B2 and the same formula gives an age.

Years and months

"YM" counts the months left over after the whole years. Join both parts into one line:

=DATEDIF(B2,$E$2,"Y")&" years, "&DATEDIF(B2,$E$2,"YM")&" months"

Ana shows 7 years, 7 months and Raj shows 4 years, 11 months.

Years with a decimal

For an average or a pay scale you may want part years too. YEARFRAC gives them, and ROUND keeps one decimal:

=ROUND(YEARFRAC(B2,$E$2),1)

Ana has 7.6 years. Use DATEDIF when you need whole years only.

Total months

"M" counts complete months from start to end:

=DATEDIF(B2,$E$2,"M")

Ana has 91 months (7 years and 7 months).

An error, or a date instead of a number

DATEDIF gives an error (#NUM! in Excel) when the start date is after the end date, for example a future start date or the two dates swapped. Show a blank instead:

=IF(B2>$E$2,"",DATEDIF(B2,$E$2,"Y"))

Ana still shows 7; a start date after E2 leaves the cell empty. If the result looks like a date in January 1900, the cell has a date format: change it to Number. Microsoft keeps DATEDIF for older Lotus 1-2-3 workbooks and advises against its "MD" unit, so stick to "Y", "M" and "YM". DATEDIF works in Excel 2016 and later, Microsoft 365 and Google Sheets.

Templates with the math already done

Rather skip the formulas? These templates come with every formula built and checked, plus a filled-in sample.

More how-tos