Excel Supreme

Excel track · Exercise 72 of 86 Paid

DATEDIF: days, months or years between

Ask for the gap between two dates in whole years, months or days, with the leftovers when needed.

Advanced

Two employees, their start dates and one review date

Read-only data · screen 1 of 2 · answer in D2

The dates in B and C are serials, not text: put the complete years Ada has served into D2, counting only full years.

ABCD
1EmployeeStartedReview dateYears served
2Ada Lovelace4456245352
3Grace Hopper4419745352

Download this grid (.xlsx) Two tabs: the grid you see, and the answer.

D2

What it does

Subtracting one date from another answers in days and nothing else. DATEDIF takes a start date, an end date and a unit in quotes, and answers in whichever unit you name. Y, M and D give whole units; YM, MD and YD give what is left after the whole ones.

Ada started on 1 January 2022 and the review is 1 March 2024, so the Y answer is 2. A subtraction on that pair gives 790 and M gives 26, both correct answers to other questions. The second screen asks for Grace's complete months and expects 38.

Nothing in the call checks that the unit matches the question, so a wrong one returns the answer to a different question. Excel leaves DATEDIF out of its function list, so type the name in full. A start date after the end returns #NUM! instead of a negative count.

Syntax

=DATEDIF(start, end, "unit")

Worked example

On Two employees, their start dates and one review date, =DATEDIF(B2,C2,"Y") returns 2.

=DATEDIF(B2,C2,"Y")

Common errors

Error codes for DATEDIF and its six units
ErrorWhat it means and how to fix it
#NUM!The end date falls before the start date, which leaves DATEDIF no positive interval to report.
#NUM!The unit in quotes is not Y, M, D, YM, MD or YD, which DATEDIF cannot count in.
#VALUE!One of the dates is text that Excel cannot read as a date, so DATEDIF has no serial to compare.

At work

A staff review sheet reporting complete years of service, without dividing a day count by 365.