How to Compute Years of Service in Excel
In this article
You compute years of service in Excel by subtracting the start date from today's date and converting the result to whole years. The standard formula is =DATEDIF(B2,TODAY(),"Y"), where B2 holds the hire date. That returns completed full years only, so someone hired 11 months ago shows 0 rather than 1. If you would rather see 4.7 years, use =(TODAY()-B2)/365 or YEARFRAC(B2,TODAY(),1) instead. If you need to show years and months together, DATEDIF with the "Y" and "YM" codes builds a text label like "7 years, 3 months".
What You'll Need
- Excel 2019, Excel 2021, Excel for Microsoft 365, or Excel for Mac. Excel for the web also supports DATEDIF. LibreOffice Calc and Google Sheets understand the same function name, though the behaviour of the start date is slightly different — see Common Mistakes.
- A column of hire dates (or contract start dates) formatted as real Excel dates, not as text. You can check this by right-aligning behaviour: a genuine date slides right by default, while text dates stay left.
- One empty column for the formula and, optionally, a second column to count months of service.
Step-by-Step
- Lay out your data. Put employee names in column A, hire dates in column B starting at B2, and leave C1 free. Type a header such as "Years of Service" in C1. Keep one row per person with no merged cells, because merged cells break copy-down and sorting.
- Verify the dates are real dates. Click a hire date and look at the formula bar. If it shows something like 15/03/2019 or 3/15/2019, it is a real date. If your dates arrived from another system and sit on the left of the cell, convert them first: select the column, open Data > Text to Columns, click Next twice, choose Date as the column format, pick the order that matches your data (DMY or MDY), and finish. This is the single most common reason the formula returns an error.
- Enter the years formula. In C2 type
=DATEDIF(B2,TODAY(),"Y")and press Enter. The first argument is the earlier date (the hire date), the second is the later date (today), and"Y"asks for complete calendar years elapsed. The result for a hire date of 15 March 2019 viewed on 4 December 2026 is 7, because the eighth anniversary has not arrived yet. - Copy it down. Select C2, hover the small square at the bottom-right corner of the cell until the cursor becomes a cross, and drag to the last row — or double-click the square to fill automatically to the end of the adjacent data. Column B references shift per row automatically.
- Add months for a fuller picture. In D2 enter
=DATEDIF(B2,TODAY(),"YM"). This returns the leftover months after the full years are counted, always between 0 and 11. Keep this in a separate numeric column rather than fusing it into text, so you can still sort and filter. - Build a readable label (optional). In E2 use
=C2&" years, "&D2&" months". To handle the singular case, wrap each part inIF:=C2&IF(C2=1," year, "," years, ")&D2&IF(D2=1," month"," months"). The result reads "7 years, 3 months" rather than "7 years, 3 months" with a stray plural. - Format the numbers. Select the years column, press Ctrl+1 (Cmd+1 on Mac) and choose the Number category with 0 decimal places so you never see 7.0. If you go the decimal route below, set 1 or 2 decimal places instead.
- Freeze a reference date for audits.
TODAY()recalculates every time the file opens, which is fine for a live report but bad for a record you need to reproduce. Put a fixed date in a cell such as H1, name it (select it, typeAsOfDatein the Name Box to the left of the formula bar, press Enter), then write=DATEDIF(B2,AsOfDate,"Y"). Every figure now matches the date you specify. - Add total service in months for pay or leave calculations. Use
=DATEDIF(B2,TODAY(),"M"), which counts whole months between the two dates. Many length-of-service policies are written in months rather than years, and this avoids rounding arguments. - Optionally show decimal years. If your HR system expects something like 7.26, use
=YEARFRAC(B2,TODAY(),1). The third argument 1 sets the day-count basis to actual/actual, which is the most accurate for ordinary calendar dates. Do not useROUNDwith zero digits on this; rounding to whole numbers quietly inflates some employees' service and understates others'. - Sort or filter the results. Select the whole table including headers, choose Data > Sort, and sort on the years column. Because the values are numbers, the order is correct; text labels like "7 years, 3 months" would sort alphabetically and put "10 years" before "7 years".
Common Mistakes
- Reversing the arguments.
DATEDIFrequires the start date first. Swap them and you get#NUM!. - Dates stored as text. A hire date typed as text will return
#VALUE!or a wildly wrong number. Fix with Text to Columns as described above, or withDATEVALUEin a helper column. - Expecting DATEDIF to appear in the function list. It is a legacy compatibility function, so Excel does not offer autocomplete or tooltips for it. Typing it manually works fine, but you have to remember the argument order yourself.
- Mixing up Y and YM.
"Y"gives whole years;"YM"gives the remaining months after those years. Using YM alone produces a number from 0 to 11 and looks broken. - Counting from a future date. If a hire date is later than today (a scheduled start), the formula returns
#NUM!. Wrap it:=IF(B2>TODAY(),"",DATEDIF(B2,TODAY(),"Y")). - Dividing by 365 only.
(TODAY()-B2)/365ignores leap years, so over a decade the figure drifts by a couple of days. UseYEARFRACif you need decimals. - Leaving blanks in the date column. Empty cells make DATEDIF return an error or a huge number because a blank counts as 0 January 1900. Wrap the formula in
=IF(B2="","",...).
Tips
- Use
TODAY()for live dashboards and a named fixed date for anything you archive or email as a record. - Anniversary-based service is what most policies mean: an employee reaches the next year on the anniversary of the hire date, not on 1 January. DATEDIF already does this.
- If your policy counts service to the end of the month or rounds up part-years, say so explicitly in a header note so nobody assumes the numbers are plain completed years.
- Keep the raw hire date column untouched and derive everything else. Deleting the source date makes every figure unreproducible.
- Use a structured table (Insert > Table) so formulas extend automatically when you add new employees.
- For multiple employees and a fixed cutoff, an
IFERRORwrapper hides the ugly#NUM!and#VALUE!errors from managers who open the file.
Troubleshooting
The formula returns #NUM!. The hire date is later than the end date, or a cell is blank. Check the argument order (start first) and add an IF guard for blanks and future dates.
You get #VALUE! or a small number like 5 when 7 is expected. The date is text. Confirm with =ISNUMBER(B2); if it returns FALSE, convert the column using Text to Columns with the correct day/month order.
The number changes every day and someone says it is wrong. That is TODAY() working as intended. Switch to a named fixed date so everyone compares against the same cutoff.
Results are off by one for people hired late in a month. DATEDIF counts complete calendar years from the exact day, so a 28 February hire and a 1 March hire reach the next year on different dates. If the policy treats all hires in a month as one group, build that rule into a separate helper column rather than editing the main formula.
The fill handle will not copy the formula. Check File > Options > Advanced > Enable fill handle and cell drag-and-drop. If the formula already copied but references stayed fixed, remove the dollar signs from B2.
DATEDIF is rejected outright. Some regional builds and very old files can mis-handle it. Fall back to =YEAR(TODAY())-YEAR(B2)-IF(DATE(YEAR(TODAY()),MONTH(B2),DAY(B2))>TODAY(),1,0), which computes the same completed-years figure.
Opening on a Mac shows different dates. The 1904 date system can shift dates by four years. Check Excel > Preferences > Calculation and align the setting with the file's origin before comparing figures.
Frequently Asked Questions
Which formula is best for years of service?
=DATEDIF(B2,TODAY(),"Y") for completed years, and YEARFRAC(B2,TODAY(),1) when you need decimals. Both are accurate; pick based on whether your policy counts full anniversaries or fractions.
Why does DATEDIF not autocomplete?
It is kept for compatibility with older spreadsheets, so Excel hides it from the function list. Type it in full and it works normally.
How do I show years and months together?
Use two helper columns, DATEDIF(...,"Y") and DATEDIF(...,"YM"), then join them with & into a label. Keeping the numbers separate preserves sorting.
Does the result update when I open the file?
Yes, if it uses TODAY(). It stays fixed if you point the formula at a named cutoff date instead.
Can I calculate service for employees who left?
Yes. Replace TODAY() with the leaving date so the formula stops counting. Keep a separate start and end column for each person.
Why is the number one lower than expected?
Because DATEDIF counts completed anniversaries, not calendar years. Someone hired in December has not finished a full year in January, so the figure correctly shows one less than a naive subtraction.