Excel tutorial
/

Functions

Intermediate

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.

Книга1 - Excel
—☐✕
D2fx=РАЗНДАТ(B2;C2;"y")
ABCDE
1EmployeeHiredAs ofService (yrs)
2Aziz02.09.201901.11.20256
3Dilnoza15.04.202101.11.20254
4Javohir01.12.202301.11.20251
5Malika20.11.201501.11.202591
6
Готово
Only complete years count. (1) Malika was hired on 20.11.2015 — on 01.11.2025 she is still 19 days short of 10 years, so the result is 9

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).
Книга1 - Excel
—☐✕
B5fx=РАЗНДАТ($D$2;$D$3;A5)
ABCDE
1UnitResultMeaningDates
2y34complete years07.05.1990
3m417complete months12.02.2025
4d12 700days
5ym9months beyond years
6yd281days beyond years
7md5days beyond months
8
Готово
From 07.05.1990 to 12.02.2025: 34 years (y), 9 months (ym) and 5 days (md). The unit can come from a cell — column A holds it without quotes

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.

Книга1 - Excel
—☐✕
D2fx=РАЗНДАТ(B2;C2;"y")
ABCDE
1EmployeeHiredAs ofService (yrs)
2Aziz02.09.2019101.11.2025263
3Dilnoza15.04.202101.11.2025
4
5
Готово
Книга1 - Excel
—☐✕
D2fx=РАЗНДАТ(B2;C2;"y")&" yrs "&РАЗНДАТ(B2;C2;"ym")&" mos "&РАЗНДАТ(B2;C2;"md")&" days"
ABCDE
1NameBornAs ofAge
2Dilnoza20.11.198501.11.202539 yrs 11 mos 12 days
3Sardor08.03.199801.11.202527 yrs 7 mos 24 days
4
5
Готово
Example 1: join "y", "ym" and "md" with & to get a full age like “39 yrs 11 mos 12 days”
Книга1 - Excel
—☐✕
D3fx=B3-ДАТАМЕС(A3;РАЗНДАТ(A3;B3;"m"))
ABCDE
1StartEnd"md" resultCorrect remainder
215.01.202510.03.20252323
331.01.202501.03.2025-21
4
5
Готово
Example 2: "md" is usually right (23 days), but from January 31 to March 1 it returns −2. The EDATE-based formula is always right: 1 day

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-B2 or =ДНИ(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.

Книга1 - Excel
—☐✕
Буфер обмена
Шрифт
Выравнивание
Число
Стили
Ячейки
Редактирование
✕✓fx
ABCDEFGHIJKLMNOPQRSTUVWX
1EmployeeHiredAs ofYearsMonths
2Aziz4371045962
3Dilnoza4430145962
4Javohir4526145962
5
6
7
8
9
10
Лист1
Готово

Has ExcelLab been useful?

Support the project and help us release new lessons and exercises.

Support us
Previous

123 / 154