Excel DATEDIF: length of service, age and years, months, days between dates
DATEDIF is Excel’s hidden function that counts complete years, months and days between two dates. Service length, age, “X years Y months Z days” and the "md" trap.
HR’s favourite question: “How many years has this employee worked here?”. Subtract two dates and you get days; divide by 365 and leap years make you wrong. DATEDIF gives the right answer: it counts complete years, months or days between two dates.
Service bonuses, an employee’s age, how many months of a loan or lease have passed — each is a single formula with this function.
The curious part: DATEDIF is a hidden function. It isn’t listed in Вставить функцию and no tooltip appears while you type, yet it works in every version of Excel.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Employee | Hired | As of | Service (yrs) | |
| 2 | Aziz | 02.09.2019 | 01.11.2025 | 6 | |
| 3 | Dilnoza | 15.04.2021 | 01.11.2025 | 4 | |
| 4 | Javohir | 01.12.2023 | 01.11.2025 | 1 | |
| 5 | Malika | 20.11.2015 | 01.11.2025 | 91 | |
| 6 |
Syntax
=РАЗНДАТ(start_date; end_date; unit)
- start_date — the starting (earlier) date.
- end_date — the ending (later) date. If it is before start_date you get #NUM!.
- unit — what to count, always in quotes:
"y"— complete years;"m"— complete months;"d"— days."ym"— months left over after complete years (0–11)."yd"— days left over after complete years."md"— days left over after complete months (careful — see below).
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Unit | Result | Meaning | Dates | |
| 2 | y | 34 | complete years | 07.05.1990 | |
| 3 | m | 417 | complete months | 12.02.2025 | |
| 4 | d | 12 700 | days | ||
| 5 | ym | 9 | months beyond years | ||
| 6 | yd | 281 | days beyond years | ||
| 7 | md | 5 | days beyond months | ||
| 8 |
Entering DATEDIF (it isn’t in the fx list)
1
Select the result cell and type the formula by hand: =РАЗНДАТ(. No argument tooltip appears — that’s normal, the function still works.
2
Click the earlier date first (B2), then the later one (C2). Order matters: reversed, you get #NUM!.
3
The third argument is the unit in quotes: "y". Close the bracket, press Enter and fill the formula down.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Employee | Hired | As of | Service (yrs) | |
| 2 | Aziz | 02.09.20191 | 01.11.20252 | 63 | |
| 3 | Dilnoza | 15.04.2021 | 01.11.2025 | ||
| 4 | |||||
| 5 |
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Name | Born | As of | Age | |
| 2 | Dilnoza | 20.11.1985 | 01.11.2025 | 39 yrs 11 mos 12 days | |
| 3 | Sardor | 08.03.1998 | 01.11.2025 | 27 yrs 7 mos 24 days | |
| 4 | |||||
| 5 |
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Start | End | "md" result | Correct remainder | |
| 2 | 15.01.2025 | 10.03.2025 | 23 | 23 | |
| 3 | 31.01.2025 | 01.03.2025 | -2 | 1 | |
| 4 | |||||
| 5 |
Pro level: DATEDIF at work
- Age/service as of today:
=РАЗНДАТ(B2;СЕГОДНЯ();"y")— refreshes each time the file opens. - Service bonus:
=ЕСЛИ(РАЗНДАТ(B2;СЕГОДНЯ();"y")>=5;10%;ЕСЛИ(РАЗНДАТ(B2;СЕГОДНЯ();"y")>=3;5%;0))— 5% from 3 years, 10% from 5 years. - Fractional years (say 6.2 years) — use
=ДОЛЯГОДА(B2;C2), not DATEDIF. - Leavers: if the leaving date is empty, use today:
=РАЗНДАТ(B2;ЕСЛИ(C2="";СЕГОДНЯ();C2);"y"). - Days only? You don’t need DATEDIF:
=C2-B2or=ДНИ(C2;B2)is enough.
Try it in the simulator
Type =РАЗНДАТ(B2;C2;"y") in D2 (complete years) and =РАЗНДАТ(B2;C2;"ym") in E2 (remaining months), then fill down to row 4. The dates are built with DATE — check them in the formula bar.
| A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | Employee | Hired | As of | Years | Months | |||||||||||||||||||
| 2 | Aziz | 43710 | 45962 | |||||||||||||||||||||
| 3 | Dilnoza | 44301 | 45962 | |||||||||||||||||||||
| 4 | Javohir | 45261 | 45962 | |||||||||||||||||||||
| 5 | ||||||||||||||||||||||||
| 6 | ||||||||||||||||||||||||
| 7 | ||||||||||||||||||||||||
| 8 | ||||||||||||||||||||||||
| 9 | ||||||||||||||||||||||||
| 10 |
Has ExcelLab been useful?
Support the project and help us release new lessons and exercises.