To calculate years of service in Excel, the most efficient method is using the =DATEDIF(start_date, end_date, "y") formula. This function calculates the difference between two dates based on a specific interval—in this case, "y" for complete years—providing a clean integer that represents the total number of full years an employee has been with a company.

What You'll Need

  • A computer with Microsoft Excel installed (works in all modern versions including Office 365, 2021, 2019, and 2016).
  • A dataset containing employee hire dates.
  • A defined end date (either a specific date or a dynamic function like TODAY()).
  • Dates formatted correctly as Date cells in Excel.

Step-by-Step

  1. Prepare Your Data Layout: Organize your spreadsheet so that employee names are in one column and their hire dates are in another. For example, place employee names in Column A and hire dates in Column B. Ensure that the dates are recognized by Excel as dates and not as text. You can verify this by selecting the cell; the Number Format dropdown in the Home tab should say "Date".
  2. Determine Your End Date: Decide if you want to calculate service up to a specific historical date or up to the current day. If you want the calculation to update automatically every time you open the file, you will use the TODAY() function. If you have a specific cutoff date (e.g., the end of a fiscal year), enter that date into a separate cell, such as cell E1, so you can reference it in your formula.
  3. Insert the DATEDIF Function: Click on the cell where you want the years of service to appear (e.g., Cell C2). Type =DATEDIF(. Note that DATEDIF is a "hidden" function in Excel; it will not appear in the autocomplete list as you type, but it is fully functional.
  4. Select the Start Date: While the parenthesis is open, click on the cell containing the employee's hire date (e.g., B2). Your formula should now look like =DATEDIF(B2,.
  5. Define the End Date: Type a comma, then select the end date. If using a fixed cell, click that cell (e.g., E1). If calculating to the current date, type TODAY(). Your formula should now look like =DATEDIF(B2, TODAY(),.
  6. Specify the Interval: Type another comma, followed by the interval code in double quotation marks. For full years of service, use "y". Close the parenthesis. The final formula should be: =DATEDIF(B2, TODAY(), "y").
  7. Execute and Apply: Press Enter. Excel will return the number of full years elapsed between the two dates. To apply this to your entire list of employees, hover your mouse over the bottom-right corner of the cell until a small black cross (the fill handle) appears. Click and drag the handle down to the bottom of your data range.
  8. Optional: Add "Years" Label: If you want the cell to say "5 Years" instead of just "5", you can modify the formula using concatenation: =DATEDIF(B2, TODAY(), "y") & " Years". Alternatively, you can use a Custom Number Format (Ctrl+1 > Number > Custom) and enter 0 "Years" to keep the value as a number for further calculations.

Common Mistakes

One of the most frequent errors is reversing the date order. The DATEDIF function requires the start date (the older date) to come first, followed by the end date (the more recent date). If you place the current date before the hire date, Excel will return a #NUM! error because it cannot calculate a negative time interval.

Another common mistake is forgetting the quotation marks around the interval code. Writing =DATEDIF(B2, TODAY(), y) without quotes will result in a #NAME? error because Excel thinks "y" is a named range or a function rather than a text string instruction.

Users also frequently struggle with date formatting. If the hire date was imported from another software as text (e.g., "2015-05-12" but stored as a string), DATEDIF will return a #VALUE! error. This happens because Excel cannot perform mathematical operations on text strings that look like dates but aren't formatted as numeric date values.

Finally, some users try to use the YEAR function (e.g., =YEAR(TODAY()) - YEAR(B2)). While this seems simpler, it is mathematically inaccurate for service calculations. The YEAR function only subtracts the calendar years. For example, if someone was hired on December 31, 2020, and today is January 1, 2021, the YEAR subtraction would say they have 1 year of service, even though they have only worked for one day. DATEDIF avoids this by only counting completed 12-month cycles.

Tips

For more detailed reporting, you can combine multiple DATEDIF functions to show years, months, and days of service in a single string. Use the "y" interval for years, "ym" for the remaining months after full years are subtracted, and "md" for the remaining days after full months are subtracted. A comprehensive formula would look like: =DATEDIF(B2, TODAY(), "y") & " Years, " & DATEDIF(B2, TODAY(), "ym") & " Months, " & DATEDIF(B2, TODAY(), "md") & " Days".

To make your spreadsheet more professional, use Conditional Formatting to highlight employees reaching milestones. For example, you can set a rule that turns a cell gold if the value is equal to 10, 20, or 25, allowing HR managers to quickly identify employees eligible for long-service awards.

If you are managing a very large dataset, consider converting your data range into an official Excel Table (Ctrl+T). When you enter the DATEDIF formula in the first row of a Table, Excel will automatically populate the formula for every subsequent row, and it will automatically include new employees added to the bottom of the list.

Troubleshooting

If your formula returns a #NUM! error, check the dates. This almost always means your start date is later than your end date. Ensure the hire date is the first argument and the current date is the second.

If you see a #VALUE! error, your dates are likely stored as text. To fix this, select the column of dates, go to the Data tab, select "Text to Columns", and immediately click "Finish". This often forces Excel to re-evaluate the cells and convert text-dates into actual date values. Alternatively, use the =DATEVALUE() function to convert the text.

If the result looks like a weird date (e.g., "1/5/1900") instead of a number like "5", it is a formatting issue. Excel sometimes tries to be helpful by formatting the result cell as a Date because the input cells were dates. To fix this, select the result cell, go to the Home tab, and change the Number Format dropdown from "Date" to "General" or "Number".

If the formula returns #NAME?, double-check your spelling of DATEDIF and ensure that the "y" is enclosed in double quotes. Ensure there are no spaces inside the quotes (e.g., " y " will not work).

Frequently Asked Questions

Does DATEDIF work in Google Sheets?

Yes, DATEDIF works in Google Sheets using the exact same syntax and interval codes as Excel.

Can I use this to calculate age?

Yes. Calculating age is identical to calculating years of service. Simply use the person's date of birth as the start date and today's date as the end date.

Why isn't DATEDIF listed in the Excel function library?

DATEDIF is a legacy function kept for compatibility with Lotus 1-2-3. While Microsoft supports it and it works in all versions, they do not include it in the autocomplete suggestions or the official function wizard.

How do I handle employees who have left the company?

Instead of using the TODAY() function, replace the end date argument with a cell reference containing the employee's termination date. This will give you the total service duration for that specific tenure.

Is there a way to calculate service in only months?

Yes. Change the interval code from "y" to "m". This will return the total number of full months elapsed between the two dates, regardless of how many years have passed.

Will this formula work across different leap years?

Yes, DATEDIF is designed to handle leap years correctly, ensuring that a full year is only counted once the same calendar date is reached in the following year.