DATEDIF

DATEDIF returns the difference between two dates in years, months, or days. The function Excel doesn't show in autocomplete but still ships - the workhorse for employee tenure, customer age, and project duration anywhere a precise human-readable interval matters.

Date & TimeIntermediate
Purpose
Return the difference between two dates in a chosen unit (years, months, days, or compound).
Returns
A whole number, the interval in the chosen unit
Syntax
=DATEDIF(start_date, end_date, unit)
Excel version
All versions since the 90s (undocumented but ships in every release)

How DATEDIF works

DATEDIF takes a start date, an end date, and a unit code in quotes. The unit decides what kind of difference to return: "Y" for completed years, "M" for completed months, "D" for days, plus three compound codes ("YM", "MD", "YD") that strip out the bigger units so you can build a "6 years, 11 months, 6 days" style readout.

Excel does NOT autocomplete the function name as you type. It still works, but you'll see no tooltip and no argument hints. You have to remember the spelling (DATEDIF, no second E) and the unit codes by hand. That undocumented status is why so many analysts have never heard of it - and why it's a quiet superpower once you know.

start_date must be earlier than or equal to end_date. If you flip them, DATEDIF returns #NUM! - it doesn't compute negative intervals. The dates can be cell references, date literals via DATE(), or strings like "2025-01-15" (locale-permitting).

= DATEDIF(start_date, end_date, unit)

Arguments

ArgumentTypeRequiredDescription
start_datedate✓ RequiredThe earlier of the two dates. Can be a cell reference, a DATE() expression, or a date literal in quotes. Must be on or before end_date.
end_datedate✓ RequiredThe later date. Same input format. Pair with TODAY() to compute "age as of right now" that recalculates daily.
unitstring✓ Required"Y" complete years · "M" complete months · "D" total days · "YM" months ignoring years · "MD" days ignoring months and years (buggy, avoid) · "YD" days ignoring years. Always in quotes.

DATEDIF "Y": complete years of tenure

The "Y" unit returns the number of full years between two dates. Partial years don't count - if an employee's anniversary hasn't happened yet in the current year, they're still last year's tenure number.

Standard HR pattern: hire date in one column, today's date or termination date in another, DATEDIF gives years of service for performance reviews, vesting calculations, or seniority lists.

=DATEDIF(A2, B2, "Y")
  • A2 -> hire date - 2018-03-15
  • B2 -> today (or any end date) - 2026-05-11
  • "Y" -> complete years only - the unit code is always in quotes
  • Result 8 -> Sarah passed her 8th anniversary on 2026-03-15 but not her 9th
  • Anniversary not yet -> If end_date were 2026-03-14 instead, the result would be 7 - one day short of the anniversary still counts as the prior year
D2
fx
=DATEDIF(A2, B2, "Y")
ABCDEFG
1Hire dateEnd dateYears
22018-03-152026-05-118← formula
32020-11-022026-05-115↓ drag down
42015-09-302026-05-1110
52024-01-082026-05-112
62017-07-222026-05-118
72021-04-102026-05-115
82013-06-012026-05-1112
92019-10-302026-05-116
102022-12-052026-05-113
112026-05-142026-05-11#NUM!
Formula entered in cell D2. Drag down for each employee row to compute their years of service.
Nine hires returning their year counts. The last row demos the #NUM! when start > end - DATEDIF does not return negative intervals.
The unit code is just one letter ("Y"), not a word ("Year" or "Years"). And it MUST be in quotes. Most "DATEDIF returned #NUM!" bugs are unit-code typos.

DATEDIF "M": complete months elapsed

The "M" unit counts full months between dates. Useful for project duration, subscription length, or any interval where days are too granular and years are too coarse.

Like Y, partial months don't count. A project that started on Jan 15 and ends on Feb 14 returns zero - the second 15th hasn't arrived yet.

=DATEDIF(A2, B2, "M")
  • A2 -> project start date
  • B2 -> project end date (or today for in-progress projects)
  • "M" -> unit code - complete months only
  • Anniversary day matters -> the result only advances when the day-of-month is reached or passed
D2
fx
=DATEDIF(A2, B2, "M")
ABCDEFG
1StartEndMonths
22025-01-152026-05-1115← formula
32025-08-202026-05-118↓ drag down
42026-02-012026-05-113
52026-04-152026-05-110
62026-03-112026-05-112
72024-06-302026-05-1122
82026-01-222026-05-113
92025-04-052026-05-1113
102023-08-112026-05-1133
112024-11-302026-05-1117
Formula entered in cell D2. The day-of-month must be reached to count as a complete month.
Row 2 (Jan 15 to May 11): 15 months, since May 11 < Jan 15 in day-of-month terms one full month is shaved off the naive 16. Row 5 returns zero because Apr 15 to May 11 is only 26 days - the next 15th hasn't arrived.

DATEDIF "D": total days between dates

The "D" unit returns the raw day count between two dates. Same as plain subtraction (B2 - A2) but the function makes the intent explicit and handles oddities like text-formatted dates more gracefully.

Common pattern: account age in days, days-since-last-login, days-until-deadline.

=DATEDIF(A2, B2, "D")
  • A2 -> earlier date
  • B2 -> later date
  • "D" -> total days, no week/month/year boundaries
  • Same as B2 - A2 -> but DATEDIF accepts more date formats than raw subtraction
D2
fx
=DATEDIF(A2, B2, "D")
ABCDEFG
1SignupTodayDays
22026-01-012026-05-11130← formula
32025-12-012026-05-11161↓ drag down
42026-04-012026-05-1140
52026-05-102026-05-111
62025-05-112026-05-11365
72024-12-252026-05-11502
82026-03-152026-05-1157
92026-04-252026-05-1116
102025-09-082026-05-11245
112022-05-112026-05-111461
Formula entered in cell D2. Each row computes the raw day count between the two dates - useful for account ages and deadline tracking.
Row 2 trace: Jan 1 to May 11. Jan has 30 days remaining + Feb 28 + Mar 31 + Apr 30 + 11 = 130. The last row spans four calendar years - 1461 days, with 2024 contributing an extra day for the leap year.

Compound output: "6 years, 11 months, 6 days"

For tenure reports and age displays, a single unit isn't enough - you want a human-readable breakdown. Stack three DATEDIF calls with the "Y", "YM", and "MD" units and concatenate the results.

"Y" gives whole years. "YM" gives the months that remain AFTER those years. "MD" gives the days that remain AFTER those months. Together they cover the full interval without double-counting.

=DATEDIF(A2,B2,"Y")&" years, "&DATEDIF(A2,B2,"YM")&" months, "&DATEDIF(A2,B2,"MD")&" days"
  • DATEDIF(A2,B2,"Y") -> 6 - complete years between Jun 5, 2019 and May 11, 2026
  • DATEDIF(A2,B2,"YM") -> 11 - months remaining after those 6 years (Jun 2025 to May 2026)
  • DATEDIF(A2,B2,"MD") -> 6 - days remaining after those 11 months (May 5 to May 11)
  • & operator -> concatenates the numbers and labels into one readable string
  • Result -> "6 years, 11 months, 6 days" - exact interval, no rounding
D2
fx
=DATEDIF(A2,B2,"Y")&" years, "&DATEDIF(A2,B2,"YM")&" months, "&DATEDIF(A2,B2,"MD")&" days"
ABCDEFGHIJ
1HireEndTenureYYMMD
22019-06-052026-05-116 years, 11 months, 6 days6116← formula
32022-09-012026-05-113 years, 8 months, 10 days3810↓ drag down
42015-01-302026-05-1111 years, 3 months, 11 days11311
52025-12-252026-05-110 years, 4 months, 16 days0416
62017-07-222026-05-118 years, 9 months, 19 days8919
72010-02-282026-05-1116 years, 2 months, 13 days16213
82023-11-152026-05-112 years, 5 months, 26 days2526
Formula entered in cell D2. Three DATEDIF calls concatenated with & to produce a human-readable tenure string. The columns to the right break out each component.
Seven date pairs in, seven readable strings out. Columns E/F/G show the individual Y/YM/MD components feeding the string in D. The breakdown is exact - no rounding, no estimation.
Wrap the whole thing in IFERROR with a fallback like "-" so a #NUM! from a flipped or missing date doesn't break the spreadsheet visually for the people reading the report.

Age calculator: DATEDIF + TODAY() for live ages

Combine DATEDIF with TODAY() and the age recalculates every time the workbook opens. A directory built this way is correct on every birthday without anyone editing the cells.

TODAY() is volatile - it updates on file open and on any recalc. The age in column C reflects today's date automatically.

=DATEDIF(B2, TODAY(), "Y")
  • B2 -> the person's date of birth
  • TODAY() -> today's date - no arguments, recalculates on open
  • "Y" -> complete years lived = current age
  • Birthday logic -> the year only increments on the day-of-month - someone born Aug 14 is still last year's age until Aug 14 comes around
D2
fx
=DATEDIF(B2, TODAY(), "Y")
ABCDEFG
1NameDate of birthAge
2Sarah Chen1992-08-1433← formula
3James Miller1985-05-0341↓ drag down
4Maria Santos1978-12-2247
5David Brown1995-02-1931
6Emma Davis2001-05-1125
7Carlos Gomez1989-09-2536
8Jenny Liu2000-04-3026
9Mark Reilly1972-07-0453
10Rachel Wood1996-11-1229
Formula entered in cell D2. As of today (2026-05-11), James and David have already had their birthdays this year; Sarah and Maria haven't yet, so their age is still last year's.
Sarah (Aug 14), Maria (Dec 22), Carlos (Sep 25), Mark (Jul 4), and Rachel (Nov 12) haven't reached their birthdays in 2026 yet - still last year's age. James, David, Jenny, and Emma have, so they're one year older. Emma's birthday is today - she just turned 25.

Where people go wrong

  1. Typing the unit without quotes or as a word

    Writing DATEDIF(A2, B2, Y) without quotes returns #NAME? because Excel interprets Y as a missing named range. Writing "Year" or "Years" returns #NUM! because Excel only accepts the single-letter codes.

    Fix: Always wrap the unit in quotes: "Y", "M", "D", "YM", "MD", "YD". Six valid codes, no synonyms, no fuzzy matching.
  2. Flipping start_date and end_date

    DATEDIF returns #NUM! if start_date > end_date. It does NOT return a negative number like raw subtraction would. People often hit this when comparing termination vs. hire date and pass them in the wrong order.

    Fix: Always pass the earlier date first. If the order might flip, wrap with IF: =IF(A2 > B2, DATEDIF(B2, A2, "D"), DATEDIF(A2, B2, "D")).
  3. Using the "MD" unit blindly

    "MD" has documented edge-case bugs in some Excel versions - it can return a negative number or skip a day around month boundaries. For "6 years, 11 months, 6 days" displays it usually works, but for production data validation it's unreliable.

    Fix: Build the compound display with "Y" and "YM" plus a derived day count from the modulo: "MD" is fine for human-readable HR reports, but never trust it for compliance or contractual calculations - cross-check with a direct subtraction.
  4. Forgetting DATEDIF is hidden from autocomplete

    Excel does not suggest DATEDIF as you type. People searching the function library don't find it. Junior analysts often "discover" tenure formulas by writing complicated SUM(...)/365 hacks instead.

    Fix: Just type it. The function exists in every version since Excel 2000. The lack of autocomplete is a UI quirk, not a "deprecated" warning - DATEDIF is fully supported.

Notes

  • DATEDIF is hidden from Excel's autocomplete and function-library UI, but it ships with every version since the 90s and is fully supported.
  • Unit codes are always in quotes: "Y", "M", "D", "YM", "MD", "YD". Other values return #NUM!.
  • start_date must be ≤ end_date. Flipping them returns #NUM!, not a negative number.
  • TODAY() recalculates on workbook open and on any sheet recalc - perfect for live age and tenure displays.
  • For compound output ("X years, Y months, Z days"), use Y + YM + MD and concatenate with & operators.
  • The "MD" unit has documented edge-case bugs - reliable enough for HR reports, unreliable for legal or compliance calculations.
  • Days result is the same as raw subtraction (B2 - A2) - DATEDIF is just more readable and tolerant of date formats.
  • Wrap with IFERROR for production reports - a single bad date in the source data turns the whole report into a column of red errors otherwise.

Now prove it

Reading about DATEDIF is one thing.

Building a payroll seniority report at 8am, where the auditor wants exact tenure to the day across 400 employees and three of them have hire dates in 1997 from the Lotus 1-2-3 era, is completely different.

These exercises drop DATEDIF into real workplace patterns: tenure listings, age verification, project SLAs, and compound display formats.

Here's the thing about DATEDIF.

You can read this page twice and still hesitate when the COO asks for a list of every employee approaching their 10-year anniversary in the next 90 days.

That gap, between knowing what DATEDIF does and being able to compose it under deadline pressure with TODAY and IFERROR and the right unit code, is exactly what CellSkill is built to close.

Not with more reading.

With practice on scenarios that look like your actual job.

Start practicing DATEDIF for free →
Free account . No credit card . Cancel anytime
Practice DATEDIF
DATEDIF in Excel: The Hidden Function for Date Math · CellSkill