Ages and Years of Service
About this lesson
An age or a length of service in Excel is DATEDIF from the earlier date to the as-of date, with the unit y. That counts only the complete years between them.
- work out an age or years of service in whole years.
- write tenure as years and months with two DATEDIFs.
The idea
Age is complete years, and only DATEDIF counts those. Subtracting the years with YEAR() is wrong for everyone whose birthday has not come yet. Dividing the days by 365.25 is wrong on and around birthdays. DATEDIF with "y" is right every day of the year. That is why a function Excel barely documents is on every HR sheet.
The remainder units are the second half of the job. "ym" gives the months past the whole years. "yd" gives the days past them. So 4 y 9 m is two DATEDIFs joined with text. The mistake is "m" where "ym" was meant. That is total months since the start, not the months since the last anniversary.
The mistake to watch for
Computing an age by subtracting years or dividing days by 365.25. Both are wrong for everyone whose birthday has not come yet this year. DATEDIF with y counts only complete years and is right every day. The second trap is m where ym was meant. That is total months since the start, not the months since the last anniversary.
Read more about this
Where this comes up again
This lesson needs JavaScript to run. Everything below is the lesson in full, but you cannot type into the grid or be marked.
In D2, type:
=DATEDIF(B2,$B$7,"y")
B7 holds the as-of date, locked so it does not move.
| Row | A | B | C | D | E | F | G | H | I |
|---|---|---|---|---|---|---|---|---|---|
| 1 | Name | Born | Started | Age | Years here | Service | Born shown | Started shown | |
| 2 | Ada | 33970 | 43617 | 1 Jan 1993 | 1 Jun 2019 | ||||
| 3 | Ben | 32344 | 44228 | 20 Jul 1988 | 1 Feb 2021 | ||||
| 4 | Cai | 36892 | 45108 | 1 Jan 2001 | 1 Jul 2023 | ||||
| 5 | Dee | 30317 | 40179 | 1 Jan 1983 | 1 Jan 2010 | ||||
| 6 | |||||||||
| 7 | As of | 45366 | |||||||
| 8 |
Every step
-
In
D2, type:=DATEDIF(B2,$B$7,"y").B7holds the as-of date, locked so it does not move. -
In
E2, useDATEDIFonC2andB7for years of service. -
Read
=DATEDIF(C3,$B$7,"m")and say what it returns for Ben, in months. -
The unit ym counts months left after whole years. In
F2, write Ada's service as 4 y 9 m. Shape:=DATEDIF(start, cell, "y")&" y "&DATEDIF(start, cell, "ym")&" m". -
The unit yd counts days since the last whole year. In
E6, useDATEDIFonC4andB7for days since Cai's anniversary. -
The unit m counts all the months, not the leftover ones. Read
=DATEDIF(C2,$B$7,"m")and say what it shows for Ada.