How to calculate years of service in Excel

This is not legal or benefits advice. A handbook can start the clock on a different day than the hire date. The sheet below counts completed calendar time from March 3, 2019 to November 16, 2026.

DATEDIF with "Y" is the completed years. The 2026 anniversary, March 3, has already passed, so the count is 7. "YM" is the completed months after those years are removed. March 3 to November 3 is 8 months. "MD" is the completed days after those months. November 3 to November 16 is 13 days.

DATEDIF
=DATEDIF(B2,B3,"Y")
=DATEDIF(B2,B3,"Y")B4
Completed service
AB
1Value
2Hired3/3/2019
3As of11/16/2026
4Years7
5Months8
6Days13
A picture of one hire date. March 3, 2019 to November 16, 2026 is 7 completed years. YM is 8 months after those years. MD is 13 days after those months. The anniversary in 2026 has passed, and November 3 to November 16 is 13 days.
=DATEDIF(DATE(2019,3,3),DATE(2026,11,16),"Y")
=DATEDIF(DATE(2019,3,3),DATE(2026,11,16),"YM")
=DATEDIF(DATE(2019,3,3),DATE(2026,11,16),"MD")

Those are 7, 8, and 13. The day of the month is 3, which exists in every month, so this "MD" result matches the calendar. The DATEDIF page flags "MD" when the dates sit near the ends of months of different lengths. Excel still calculates DATEDIF and still hides it in the function list. Type the name.

"D" is the whole span in days, 2,815:

=DATEDIF(DATE(2019,3,3),DATE(2026,11,16),"D")

xl.age.ymd spills the same three numbers, 7, 8, and 13:

=xl.age.ymd(DATE(2019,3,3), DATE(2026,11,16))

The name needs Microsoft 365, Excel 2024, or Excel for the web. Excel 2021 returns #NAME?. The three DATEDIF calls work without it. Saving the name is the same Name Manager step as the LAMBDA how-to. The age page uses a different pair, March 15, 1990 to November 11, 2026, which is 36 years, 7 months, and 27 days.

The fraction of a year

YEARFRAC with basis 1 is the actual-day fraction:

=YEARFRAC(DATE(2019,3,3),DATE(2026,11,16),1)

The full value is 7.707049966. Six decimals show 7.707050. Leave the basis off and Excel uses the 30/360 US count instead. 2,815 / 365 is 7.712329. That division ignores the leap days in 2020 and 2024, so it is not the basis 1 result.

YEARFRAC
=YEARFRAC(B2,B3,1)
=YEARFRAC(B2,B3,1)B4
Year fraction
AB
1Value
2Hired3/3/2019
3As of11/16/2026
4Fraction7.707050
A picture of the same two dates with basis 1. The full value is 7.707049966, which shows as 7.707050 at six decimals. Dividing the 2,815 days by 365 is 7.712329, a different number.

The workbook that can sit next to a hire date is the PTO tracker.


Template for this article

PTO Tracker

More from the blog