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).
Arguments
| Argument | Type | Required | Description |
|---|---|---|---|
| start_date | date | ✓ Required | The 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_date | date | ✓ Required | The later date. Same input format. Pair with TODAY() to compute "age as of right now" that recalculates daily. |
| unit | string | ✓ 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
| A | B | C | D | E | F | G | |
|---|---|---|---|---|---|---|---|
| 1 | Hire date | End date | Years | ||||
| 2 | 2018-03-15 | 2026-05-11 | 8 | ← formula | |||
| 3 | 2020-11-02 | 2026-05-11 | 5 | ↓ drag down | |||
| 4 | 2015-09-30 | 2026-05-11 | 10 | ||||
| 5 | 2024-01-08 | 2026-05-11 | 2 | ||||
| 6 | 2017-07-22 | 2026-05-11 | 8 | ||||
| 7 | 2021-04-10 | 2026-05-11 | 5 | ||||
| 8 | 2013-06-01 | 2026-05-11 | 12 | ||||
| 9 | 2019-10-30 | 2026-05-11 | 6 | ||||
| 10 | 2022-12-05 | 2026-05-11 | 3 | ||||
| 11 | 2026-05-14 | 2026-05-11 | #NUM! |
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
| A | B | C | D | E | F | G | |
|---|---|---|---|---|---|---|---|
| 1 | Start | End | Months | ||||
| 2 | 2025-01-15 | 2026-05-11 | 15 | ← formula | |||
| 3 | 2025-08-20 | 2026-05-11 | 8 | ↓ drag down | |||
| 4 | 2026-02-01 | 2026-05-11 | 3 | ||||
| 5 | 2026-04-15 | 2026-05-11 | 0 | ||||
| 6 | 2026-03-11 | 2026-05-11 | 2 | ||||
| 7 | 2024-06-30 | 2026-05-11 | 22 | ||||
| 8 | 2026-01-22 | 2026-05-11 | 3 | ||||
| 9 | 2025-04-05 | 2026-05-11 | 13 | ||||
| 10 | 2023-08-11 | 2026-05-11 | 33 | ||||
| 11 | 2024-11-30 | 2026-05-11 | 17 |
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
| A | B | C | D | E | F | G | |
|---|---|---|---|---|---|---|---|
| 1 | Signup | Today | Days | ||||
| 2 | 2026-01-01 | 2026-05-11 | 130 | ← formula | |||
| 3 | 2025-12-01 | 2026-05-11 | 161 | ↓ drag down | |||
| 4 | 2026-04-01 | 2026-05-11 | 40 | ||||
| 5 | 2026-05-10 | 2026-05-11 | 1 | ||||
| 6 | 2025-05-11 | 2026-05-11 | 365 | ||||
| 7 | 2024-12-25 | 2026-05-11 | 502 | ||||
| 8 | 2026-03-15 | 2026-05-11 | 57 | ||||
| 9 | 2026-04-25 | 2026-05-11 | 16 | ||||
| 10 | 2025-09-08 | 2026-05-11 | 245 | ||||
| 11 | 2022-05-11 | 2026-05-11 | 1461 |
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
| A | B | C | D | E | F | G | H | I | J | |
|---|---|---|---|---|---|---|---|---|---|---|
| 1 | Hire | End | Tenure | Y | YM | MD | ||||
| 2 | 2019-06-05 | 2026-05-11 | 6 years, 11 months, 6 days | 6 | 11 | 6 | ← formula | |||
| 3 | 2022-09-01 | 2026-05-11 | 3 years, 8 months, 10 days | 3 | 8 | 10 | ↓ drag down | |||
| 4 | 2015-01-30 | 2026-05-11 | 11 years, 3 months, 11 days | 11 | 3 | 11 | ||||
| 5 | 2025-12-25 | 2026-05-11 | 0 years, 4 months, 16 days | 0 | 4 | 16 | ||||
| 6 | 2017-07-22 | 2026-05-11 | 8 years, 9 months, 19 days | 8 | 9 | 19 | ||||
| 7 | 2010-02-28 | 2026-05-11 | 16 years, 2 months, 13 days | 16 | 2 | 13 | ||||
| 8 | 2023-11-15 | 2026-05-11 | 2 years, 5 months, 26 days | 2 | 5 | 26 |
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
| A | B | C | D | E | F | G | |
|---|---|---|---|---|---|---|---|
| 1 | Name | Date of birth | Age | ||||
| 2 | Sarah Chen | 1992-08-14 | 33 | ← formula | |||
| 3 | James Miller | 1985-05-03 | 41 | ↓ drag down | |||
| 4 | Maria Santos | 1978-12-22 | 47 | ||||
| 5 | David Brown | 1995-02-19 | 31 | ||||
| 6 | Emma Davis | 2001-05-11 | 25 | ||||
| 7 | Carlos Gomez | 1989-09-25 | 36 | ||||
| 8 | Jenny Liu | 2000-04-30 | 26 | ||||
| 9 | Mark Reilly | 1972-07-04 | 53 | ||||
| 10 | Rachel Wood | 1996-11-12 | 29 |
Where people go wrong
- 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. - 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")). - 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. - 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 →