How to Calculate Years of Service in Excel with Optional Leave Dates
Question details
The user needs a single Excel formula to calculate the total completed years of service based on a hire date and an optional leave date, automatically substituting today's date if the leave date is blank.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Calculating employee tenure or years of service in an HR or management spreadsheet without manually updating today's date for active employees.
- Observed behavior
- The user requires an automated calculation where missing leave dates dynamically trigger a calculation up to the current date using the TODAY() function.
Ensure that your hire dates and existing leave dates are correctly formatted as Dates in your spreadsheet so the formula can process the values accurately.
Use the DATEDIF and IF Functions Together
Combine the DATEDIF function with a nested IF statement to automatically substitute the current date when an employee's leave date cell is empty.
The DATEDIF function calculates the difference between two dates. By nesting an IF function inside it, you can instruct Excel to check if the leave date is provided. If it is blank, the TODAY() function acts as the end date.
Make sure your hire dates are in column C and leave dates are in column D. Select both columns, right-click, choose 'Format Cells', and select 'Date' from the Number tab.
In your dedicated service-years column (e.g., cell E2), type the following formula: =IF(C2="","",DATEDIF(C2,IF(D2="",TODAY(),D2),"Y")) and press Enter.
Click on cell E2 again. Hover your cursor over the bottom-right corner until it turns into a plus sign (+), then click and drag the fill handle down to apply the formula to the rest of your employee data.

Calculate Exact Fractional Years with YEARFRAC
If you need exact decimals for partial years instead of strictly completed years, use the YEARFRAC function paired with the IF function.
Calculate Employee Tenure Easily in WPS Spreadsheet
WPS Spreadsheet provides full support for advanced data calculation functions like DATEDIF and YEARFRAC, allowing you to manage HR data, calculate service years, and automate your workflow with incredible ease.
- 1. Open your HR data in WPS Spreadsheet: Launch WPS Office and open your employee records workbook containing the hire and leave dates.
- 2. Apply the DATEDIF formula: Type =IF(C2="","",DATEDIF(C2,IF(D2="",TODAY(),D2),"Y")) into the target service-years cell.
- 3. Drag to fill the column: Double-click the fill handle in the lower-right corner of the cell to instantly calculate years of service for all employees.

Frequently Asked Questions
Why is my DATEDIF formula returning a #NUM! error?
This error occurs if the hire date in column C is later than the leave date or today's date. Ensure that all hire dates are properly formatted as dates and chronologically occur before the end dates.
How can I include months and days in the tenure calculation?
You can combine multiple DATEDIF functions using the ampersand (&). For example: =DATEDIF(C2,TODAY(),"Y") & " Years " & DATEDIF(C2,TODAY(),"YM") & " Months" to get a detailed breakdown of service time.
Does the TODAY() function update automatically?
Yes, the TODAY() function is volatile. This means it will automatically refresh to the current date every time you open, modify, or recalculate the workbook.
How do I calculate years of service excluding unpaid leave?
To exclude unpaid leave, you will need a separate helper column calculating the total days of unpaid leave. You would then subtract those specific days from the total difference between the hire and end dates before dividing the result by 365.




