ExcelReady
CourseMock testsFunction guidesBlog
Start freeStart learning for free
ExcelReady

Be Excel-ready before day one. Hands-on practice in your browser, with instant feedback.

Learn

  • Course
  • Mock tests
  • Function guides
  • Blog

Test prep

  • Excel level test
  • Excel test practice
  • Free screening quiz
  • Certificate

Company

  • About
  • Editorial policy
  • Contact
  • Terms
  • Privacy

© 2026 ExcelReady. All rights reserved.

  1. Blog
  2. Comparisons
  3. DATEDIF vs YEARFRAC: Ages and Years Between Dates

DATEDIF vs YEARFRAC: Ages and Years Between Dates

By ExcelReady Team·Updated November 2, 2026·6 min read

The short answer

DATEDIF counts complete years, months or days between two dates, so it is the right choice for ages and "6 years, 5 months" tenure. YEARFRAC returns the years as a decimal, such as 6.49, which suits prorating pay, bonuses and averages. For a person's age, use DATEDIF with "Y": INT(YEARFRAC) can be one year short on a birthday.

Key takeaways

  • DATEDIF returns whole units: "Y" for completed years, "M" for months, "YM" for months left over.
  • YEARFRAC returns a decimal number of years, and its basis argument decides how days are counted.
  • For ages, use DATEDIF with "Y". INT(YEARFRAC) can be a year short exactly on a birthday.
  • DATEDIF gives #NUM! if the start date is later than the end date. YEARFRAC accepts either order.
  • Use YEARFRAC with basis 1 for prorating, and match a contract's day-count rule if it names one.
On this page+
  1. DATEDIF vs YEARFRAC at a glance
  2. How the syntax differs
  3. The same dates, side by side
  4. Which is better for age: DATEDIF or YEARFRAC?
  5. When to use DATEDIF
  6. When to use YEARFRAC
  7. Common mistakes with DATEDIF and YEARFRAC
  8. Our recommendation
  9. Practise it

The short answer to DATEDIF vs YEARFRAC: DATEDIF counts complete years, months or days, and YEARFRAC returns the years as a decimal. Use DATEDIF when you need an age or "6 years, 5 months" of service. Use YEARFRAC when you need the fraction, for example to prorate a bonus. This guide is for anyone in HR, payroll or admin who works with start dates, birthdays and contract dates.

DATEDIF vs YEARFRAC at a glance#

DATEDIF answers "how many whole years?", and YEARFRAC answers "how many years, exactly?".

FeatureDATEDIFYEARFRAC
Syntax=DATEDIF(start_date, end_date, unit)=YEARFRAC(start_date, end_date, [basis])
ReturnsWhole years, months or daysA decimal number of years
Example result6 (years)6.49
Units"Y", "M", "D", "YM", "YD", "MD"Always years
Day-count optionsNoneFive bases (0 to 4)
Start date later than end date#NUM!Works, returns a positive number
In the function list and tooltipsNo (you type it in full)Yes
Best forAges, tenure, "X years Y months"Prorating, averages, decimal service
Excel versionsAll versionsAll versions

How the syntax differs#

Both functions take a start date and an end date. DATEDIF then needs a unit in quotes, and YEARFRAC takes an optional basis number.

Excel formula
=DATEDIF(start_date, end_date, unit)
=YEARFRAC(start_date, end_date, [basis])

DATEDIF units:

  • "Y": complete years.
  • "M": complete months.
  • "D": days.
  • "YM": months left over after the complete years.
  • "YD": days left over after the complete years, ignoring the year.
  • "MD": days left over after the complete months. Microsoft warns this unit can give wrong results, so avoid it.

YEARFRAC's basis sets the day-count rule: 0 or blank is US 30/360, 1 is actual/actual, 2 is actual/360, 3 is actual/365 and 4 is European 30/360. For HR and everyday business work, use 1, which counts real days and real year lengths. The YEARFRAC guide explains every basis in detail, and the DATEDIF function guide covers each unit.

The same dates, side by side#

Here are four employees, with an as-of date of 10 Sep 2025:

ABC
1EmployeeStartAs of
2Ana15 Mar 201910 Sep 2025
3Ben1 Nov 202110 Sep 2025
4Chloe30 Jun 201510 Sep 2025
5Dev8 Jan 202410 Sep 2025

These are the results of four formulas in row 2, filled down:

EmployeeDATEDIF(B2,C2,"Y")DATEDIF(B2,C2,"YM")YEARFRAC(B2,C2,1)YEARFRAC(B2,C2)
Ana656.49086.4861
Ben3103.85823.8583
Chloe10210.197910.1944
Dev181.67171.6722

DATEDIF tells you Ana has worked 6 complete years and 5 more months. Join the two for a readable label:

Excel formula
=DATEDIF(B2,C2,"Y")&" years, "&DATEDIF(B2,C2,"YM")&" months"

The result is 6 years, 5 months. YEARFRAC tells you the same service is 6.49 years, which you can multiply, average or chart. The last column uses the default basis 0 (30/360), so its results differ slightly from basis 1.

Which is better for age: DATEDIF or YEARFRAC?#

For ages, DATEDIF with "Y" is the safer choice, because it counts a year only when the birthday has been reached. Many people write =INT(YEARFRAC(B2,C2,1)) instead, and it usually gives the same number. Exactly on a birthday it can be one short.

Take someone born on 4 Sep 1988, checked on 4 Sep 2021, their 33rd birthday:

Excel formula
=DATEDIF(DATE(1988,9,4),DATE(2021,9,4),"Y")
=INT(YEARFRAC(DATE(1988,9,4),DATE(2021,9,4),1))

DATEDIF returns 33. YEARFRAC with basis 1 returns about 32.998, because over many years it divides the days by an average year length, so INT gives 32. The default basis has its own trap: for someone born on 31 May 1990, =YEARFRAC(DATE(1990,5,31),DATE(2025,5,30)) returns exactly 35, a day before the 35th birthday, while DATEDIF correctly returns 34.

For a rule like "must be 18 or older", one year off is a real error. The guide on calculating age and tenure in Excel shows full age formulas with today's date.

When to use DATEDIF#

Use DATEDIF when the answer must be in whole units. It is the right choice for:

  • Ages and age checks, such as eligibility at 18 or 65.
  • Tenure in years and months, like "6 years, 5 months" on a staff list.
  • Service milestones, such as flagging everyone with 10 or more complete years.
  • Complete months between two dates, for example months on a contract with "M".

DATEDIF needs the earlier date first. If the dates could be blank or reversed, guard it: =IF(C2>=B2,DATEDIF(B2,C2,"Y"),""). If you only need the number of days, subtraction or DAYS is simpler; see DAYS vs DATEDIF.

When to use YEARFRAC#

Use YEARFRAC when the part of a year matters. It is the better choice for:

  • Prorating pay or bonuses. An annual bonus of 3,000 for someone who joined on 1 Apr 2025, measured to 31 Dec 2025: =3000*YEARFRAC(DATE(2025,4,1),DATE(2025,12,31),1) returns 2,252.05 (274 days out of 365).
  • Average tenure across a team, where 6.49 is more accurate than 6.
  • Interest and finance, where a contract names a day count like 30/360. Match the basis to the contract.
  • Charts of service length, which look smoother with decimals.

To show a rounded decimal, wrap it: =ROUND(YEARFRAC(B2,C2,1),2) gives 6.49 for Ana.

Common mistakes with DATEDIF and YEARFRAC#

These slips cause most wrong answers:

  1. Dates in the wrong order in DATEDIF. A start date after the end date gives #NUM!.
  2. Forgetting the quotes around the unit. =DATEDIF(B2,C2,Y) gives #NAME?. Write "Y".
  3. Using INT(YEARFRAC) for exact ages. It can be a year short on a birthday, as shown above.
  4. Leaving out the basis. YEARFRAC's default is 30/360, not real days. Add 1 unless a policy says otherwise.
  5. Dates stored as text. If a date sits on the left of the cell, Excel may see text and return #VALUE!. Convert it with DATEVALUE.
  6. Trusting "MD". Microsoft warns that this DATEDIF unit can return wrong values. Calculate leftover days another way.

If you work with deadlines rather than past dates, see how many days until a deadline, and for plain day counts, how to count days between dates.

Our recommendation#

Use DATEDIF whenever you need whole years or months: ages, eligibility and tenure labels. Use YEARFRAC with basis 1 whenever you need the fraction: prorated pay, averages and decimal service. Don't turn YEARFRAC into whole years with INT for anything that has a legal or policy edge, such as an age limit.

In short: DATEDIF for "how many complete years", YEARFRAC for "how much of a year".

Practise it#

Try the YEARFRAC exercise on this page, then switch to whole years with DATEDIF in the days between dates lesson. You type each formula in a live spreadsheet and it is checked instantly, from simple day counts to tenure in years and months.

Try it yourself

This is a live spreadsheet. Type the formula in the green cell and press Enter.

How many years has Ana worked, as a decimal? In D2, use YEARFRAC with basis 1 on her start date (B2) and the as-of date (C2), and round it to 2 decimal places: =ROUND(YEARFRAC(B2,C2,1),2).

fx
ABCDE
1
Employee
Start
As of
Years
2
Ana
43539
45910
3
Ben
44501
45910
4
Chloe
42185
45910
5
Dev
45299
45910
6
7
8

Tip: YEARFRAC takes the start date, the end date and the basis (1). Put the whole thing inside ROUND with 2 decimals.

Practise this in a lesson

LessonDays between dates: DAYS, DATEDIF and TODAYMeasure the gap between two dates in days, months and years, and calculate tenure as of today.Function guideDATEDIFCalculate tenure, age and contract length with DATEDIF. Learn every unit (Y, M, D, YM), the hidden-function quirks, and practice live.

Frequently asked questions

What is the difference between DATEDIF and YEARFRAC?

+

DATEDIF counts complete units, such as 6 whole years. YEARFRAC returns the exact fraction of years, such as 6.49. Use DATEDIF for ages and tenure, and YEARFRAC for prorating and averages.

Which is better for calculating age in Excel?

+

DATEDIF with "Y", for example =DATEDIF(B2,C2,"Y"). It counts a year only when the birthday has been reached, and it gives the right age on the birthday itself.

Why doesn't DATEDIF appear in Excel's function list?

+

DATEDIF is an older function kept for compatibility. Excel doesn't suggest it as you type or list it in Insert Function, but it works in every current version when you type it in full.

Can YEARFRAC give whole years?

+

Wrap it in INT or ROUNDDOWN, such as =INT(YEARFRAC(B2,C2,1)). Be careful around birthdays and anniversaries, where the result can be one year short. DATEDIF is safer for whole years.

What does the basis mean in YEARFRAC?

+

The basis is the day-count rule. 0 or blank is US 30/360, 1 is actual days over actual year length, 2 is actual/360, 3 is actual/365 and 4 is European 30/360. Basis 1 suits most HR and business work.

Sources

  • DATEDIF function - Microsoft Support
  • YEARFRAC function - Microsoft Support

Written and checked by the ExcelReady Team. First published November 2, 2026. The practice exercise runs in the same formula engine as our lessons. Found a mistake? Read our editorial policy or email hello@excelready.app.

On this page

  1. DATEDIF vs YEARFRAC at a glance
  2. How the syntax differs
  3. The same dates, side by side
  4. Which is better for age: DATEDIF or YEARFRAC?
  5. When to use DATEDIF
  6. When to use YEARFRAC
  7. Common mistakes with DATEDIF and YEARFRAC
  8. Our recommendation
  9. Practise it

Keep reading

Comparisons· 7 min read

DAYS vs DATEDIF vs Subtracting Dates in Excel

To count days, subtracting dates (=C2-B2) and DAYS(end, start) give the same answer. Use DATEDIF(start, end, unit) when you need complete years or months, such as tenure or age. Watch the order: DAYS takes the end date first, DATEDIF takes the start date first, and DATEDIF returns #NUM! if the start is later.

Dates· 7 min read

YEARFRAC in Excel: Part of a Year Between Two Dates

YEARFRAC returns the time between two dates as a fraction of a year, such as 0.5 for six months. Write =YEARFRAC(start_date, end_date, [basis]). Use basis 1 (actual days) for tenure, age and prorating; the default, basis 0, treats every month as 30 days, as many US finance calculations do. Wrap it in INT for whole years.

Dates· 6 min read

Calculate Age or Years of Service in Excel

To calculate age in Excel, use =DATEDIF(B2,TODAY(),"Y"), where B2 is the birth date. It counts complete years, so the age only goes up on the birthday. Years of service work the same way with the hire date. For a report that must not change, replace TODAY() with a fixed "as of" date cell.

More on comparisons

  • EDATE vs EOMONTH: Adding Months the Right Way
  • EXACT vs = in Excel: Case-Sensitive Comparisons
  • Excel 365 vs 2021 vs 2019: Which Functions You Get
  • Excel Desktop vs Excel for the Web
  • Excel on Mac vs Windows: Shortcuts and Differences
  • Excel Table vs Pivot Table: What Each One Does
All comparisons articles →

Don't just read about Excel. Do it.

Practise real formulas in a live spreadsheet with instant feedback, right in your browser. Nothing to download.

Start learning for free