ExcelReady
CourseFunction guidesPricing
Plan my prepStart freeStart learning for free
ExcelReady

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

Learn

  • Course
  • Function guides
  • Plan my prep

Product

  • Pricing
  • Certificate
  • Brand kit

Company

  • Contact
  • Terms
  • Privacy

© 2026 ExcelReady. All rights reserved.

Function guides / DATEDIF

The DATEDIF function in Excel

DATEDIF measures the gap between two dates in complete years, months or days. It's the standard way to work out employee tenure, a customer's age or how long a subscription ran. It's a "hidden" function that Excel doesn't autocomplete, but it works in every version and turns up regularly in HR and finance tests.

Syntax

=DATEDIF(start_date, end_date, unit)
start_dateThe earlier date.
end_dateThe later date. If it's before start_date, you get #NUM!.
unitWhat to count, in quotes: "Y" full years, "M" full months, "D" days, "YM" months left over after full years, "MD" days left over after full months, "YD" days left over after full years.

Try it yourself

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

In D2, use DATEDIF to calculate how many complete months the customer was subscribed, from the start date in B2 to the end date in C2.

fx
ABCDEFG
1
Customer
Start date
End date
Months
2
Lakeside Gym
1/20/2023
6/5/2024
3
Copperleaf Café
9/1/2022
2/29/2024
4
Vela Architects
5/12/2023
11/30/2023
5
Fennel & Rye
3/15/2021
3/14/2024
6
7
8

Tip: Start date first, end date second, then the unit for whole months in quotes.

Examples

=DATEDIF(B2,C2,"Y")→ 5

Counts the complete years between Ana's hire date and her review. A year only counts once it's fully finished.

=DATEDIF(B3,C3,"M")→ 40

Counts complete months instead, which is better for short tenures like Ben's.

=DATEDIF(B4,C4,"Y")&" years, "&DATEDIF(B4,C4,"YM")&" months"→ "8 years, 8 months"

Combines two units into a readable label: full years, then the months left over after those years.

Example data

1EmployeeHire dateReview date
2Ana Ruiz4/15/20193/31/2025
3Ben Okoro11/1/20213/31/2025
4Chloé Martin7/20/20163/31/2025

Common mistakes

  • Start and end dates swapped

    DATEDIF returns #NUM! when the start date is later than the end date. The earlier date always goes first.

  • Unit without quotes

    DATEDIF(B2,C2,Y) returns #NAME?. The unit is text: "Y".

  • Dates stored as text

    A date typed as text, such as one imported from a CSV, returns #VALUE!. Convert it to a real date, or build one with DATE(year,month,day).

  • Trusting the "MD" unit

    "MD" can give odd results around month ends. For leftover days, subtract dates directly or use "D" for total days.

FAQ

How do I calculate age in Excel?+

Use the birth date and today's date: =DATEDIF(B2,TODAY(),"Y"). It returns completed years, so the age only goes up on the birthday.

Why can't I find DATEDIF in Excel's function list?+

It's kept for compatibility with older spreadsheet programs, so Excel doesn't suggest it or show tooltips. Type the full formula and it works.

How do I get the number of days between two dates?+

Subtract them, =C2-B2, or use =DAYS(C2,B2). DATEDIF(B2,C2,"D") gives the same answer.

Lesson

Master DATEDIF step by step: Days between dates: DAYS, DATEDIF and TODAY

Measure the gap between two dates in days, months and years, and calculate tenure as of today.

Related functions

IFTEXTJOINROUND