How to Calculate Exact Age and Elapsed Time in Microsoft Excel Using DATEDIF

Calculating elapsed time—such as an employee’s exact age, completed company service tenure, equipment warranty periods, or contractual project milestones—presents subtle mathematical challenges in spreadsheets. Standard subtraction formulas (such as (End_Date - Start_Date) / 365.25) yield decimal fractions that produce rounding errors when factoring in leap years, month boundaries, and variable month lengths. While modern Excel functions like YEARFRAC provide decimal approximations, calculating exact completed calendar years, months, and days requires the specialized DATEDIF function.

Although DATEDIF remains unlisted in Excel’s formula autocomplete menu for legacy compatibility reasons, it is fully supported across all versions of Microsoft Excel and provides precise calendar interval calculations.

Syntax and Unit Parameters of the DATEDIF Function

The DATEDIF (“Date Difference”) function accepts three core parameters:

=DATEDIF(start_date, end_date, unit)

Understanding the arguments is essential to prevent calculation errors:

  • start_date: The beginning date of the period, entered as a date serial or reference to a valid date cell.
  • end_date: The concluding date of the period. Crucial rule: start_date must always be earlier than or equal to end_date, otherwise Excel returns a #NUM! error.
  • unit: A text code enclosed in quotation marks that dictates what unit of measurement Excel returns:
    • "Y": Total completed full years between dates.
    • "M": Total completed full months between dates.
    • "D": Total elapsed days between dates.
    • "YM": Remaining months after excluding completed full years (returns 0 to 11).
    • "YD": Remaining days after excluding completed full years (returns 0 to 365).
    • "MD": Remaining days after excluding completed full months (returns 0 to 30).

Calculating Current Age in Completed Years

To calculate a person’s current age based on their birth date:

  1. Assume the date of birth is entered in cell B2 (e.g. 15/04/1990).
  2. In cell C2, enter the formula pairing DATEDIF with the dynamic TODAY() function:
=DATEDIF(B2, TODAY(), "Y")
  1. Press Enter. Excel calculates completed full years accurately. On the employee’s birthday, the calculated age will automatically increment by one.

Building a Complete “X Years, Y Months, Z Days” Tenure String

In human resources and legal contracts, service duration must frequently be displayed in complete conversational units:

  1. Assume an employee’s hire date is in cell B2 and their departure date (or current date) is in cell C2.
  2. Enter the following concatenated formula:
=DATEDIF(B2, C2, "Y") & " Years, " & DATEDIF(B2, C2, "YM") & " Months, " & DATEDIF(B2, C2, "MD") & " Days"
  1. The formula operates by combining three distinct intervals:
    • DATEDIF(B2, C2, "Y") extracts the total integer years.
    • DATEDIF(B2, C2, "YM") calculates the remaining months after accounting for those years.
    • DATEDIF(B2, C2, "MD") extracts the residual days after accounting for completed months.
  2. A date range from 15 January 2020 to 20 August 2025 evaluates cleanly to: 5 Years, 7 Months, 5 Days.

Handling Month-End Edge Cases and Best Practices

When working with DATEDIF across varying calendar boundaries, be mindful of specific computational nuances:

  • The “MD” Parameter Boundary Behavior: Due to historical compatibility with Lotus 1-2-3, comparing dates that span month ends (for example, comparing 31 January to 1 March) can occasionally cause the "MD" argument to return minor offset discrepancies depending on whether the year is a leap year.
  • Reliable Residual Days Alternative: If absolute precision is required across short irregular month boundaries, calculate residual days using the modern EDATE function:
=C2 - EDATE(B2, DATEDIF(B2, C2, "M"))

This subtracts the date of the exact completed month anniversary from the end date, ensuring that remaining days accurately mirror true calendar spacing.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.