Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Age Calculation Between Two Dates in Excel

· 4 min read · Home Tech

In this article
  1. Background and Purpose of Age Calculation
  2. How DATEDIF Works
  3. Step-by-Step Age Calculation
  4. Common Problems and Limitations
  5. Alternatives and Workarounds
  6. Frequently Asked Questions

Age calculation between two dates in Excel is most accurately done using the DATEDIF function, which computes the difference in years, months, or days between a start date and an end date. This function is hidden but fully functional and designed specifically for calculating time intervals, such as age, tenure, or project duration.

Background and Purpose of Age Calculation

Calculating age or time differences between two dates is a common need in personal, academic, and professional settings. Examples include determining a person’s age for medical records, calculating employee tenure, or tracking project timelines. While Excel lacks a visible 'Age' function, it provides powerful date arithmetic tools. The most reliable method is the DATEDIF function, which has been part of Excel since Lotus 1-2-3 compatibility days, though Microsoft does not officially document it in the function library.

Excel stores dates as serial numbers, where January 1, 1900, is 1, and each subsequent day increments by 1. This system allows straightforward subtraction: subtracting one date from another gives the number of days between them. However, converting this into human-readable years, months, and days requires more precision—especially when accounting for leap years and variable month lengths. That’s where DATEDIF excels.

How DATEDIF Works

The DATEDIF function takes three arguments: start date, end date, and a unit code that specifies the type of difference to return. The syntax is:

  1. start_date: The earlier date (e.g., birth date)
  2. end_date: The later date (e.g., today’s date)
  3. unit: A text code defining the output format

The available unit codes are:

  • "Y" – Complete years between the dates
  • "M" – Complete months between the dates
  • "D" – Total days between the dates
  • "MD" – Days between the dates, ignoring months and years (can be unreliable due to month-end edge cases)
  • "YM" – Months between the dates, ignoring years
  • "YD" – Days between the dates, ignoring years (best for ages under one year)

For example, to calculate someone’s age in full years:

=DATEDIF(A2, B2, "Y")

Where A2 contains the birth date and B2 the current date.

Step-by-Step Age Calculation

To calculate age in years, months, and days:

  1. Enter the birth date in cell A2 (e.g., 1/15/1990)
  2. Enter the current date in cell B2 (e.g., TODAY() or a specific date)
  3. In cell C2, calculate years: =DATEDIF(A2, B2, "Y")
  4. In cell D2, calculate remaining months: =DATEDIF(A2, B2, "YM")
  5. In cell E2, calculate remaining days: =DATEDIF(A2, B2, "MD")
  6. Combine into a readable string: =C2 & " years, " & D2 & " months, " & E2 & " days"

This method accounts for leap years and varying month lengths. Using TODAY() as the end date ensures the age updates automatically.

Common Problems and Limitations

Despite its usefulness, DATEDIF has known issues:

  • Hidden function: It does not appear in the function list or autocomplete, leading many users to overlook it.
  • "MD" unit inaccuracy: When the start date is the 31st and the end month has fewer days, "MD" may return negative or incorrect values. For example, from January 31, 2020, to March 1, 2020, "MD" returns -2.
  • End date before start date: Returns a #NUM! error. Always ensure the end date is later.
  • Invalid dates: Text that looks like a date but isn’t recognized (e.g., "Feb 30") causes errors.

Avoid using simple subtraction for age in years, such as (TODAY()-A2)/365.25, because it assumes all years are equal and can be off by a year near birthdays. DATEDIF correctly checks whether the birthday has occurred this year.

Alternatives and Workarounds

When DATEDIF is not preferred, alternatives include:

  • YEARFRAC function: Returns the fraction of a year between two dates. Use FLOOR(YEARFRAC(start, end), 1) to get whole years. However, it uses different day-count conventions and may not match calendar years exactly.
  • Manual calculation with YEAR, MONTH, DAY: Complex nested IF statements can compute age, but they are error-prone and harder to maintain.
  • Power Query or VBA: For advanced users, custom functions can encapsulate the logic, but these require additional setup.

Despite these options, DATEDIF remains the most accurate and widely accepted method for age calculation in Excel.

Frequently Asked Questions

Why doesn’t DATEDIF show up in Excel’s function list?
DATEDIF is a legacy function retained for compatibility with older spreadsheet programs. Microsoft does not actively promote it due to the "MD" unit bug, but it remains fully functional and safe to use.

Can I use DATEDIF to calculate age as a decimal?
Not directly. DATEDIF returns whole units. To get age in decimal years, use YEARFRAC(start_date, end_date), which calculates the proportion of the year completed.

What if the birth date is in the future?
If the start date is later than the end date, DATEDIF returns a #NUM! error. Use an IF statement to handle this: =IF(A2>B2, "Invalid", DATEDIF(A2,B2,"Y")).

How do I calculate age on a specific date, not today?
Replace TODAY() with the target date. For example, to find age on January 1, 2025: =DATEDIF(A2, DATE(2025,1,1), "Y").

Is DATEDIF available in Excel for Mac and online?
Yes. DATEDIF works in all modern versions of Excel, including desktop (Windows and Mac), Excel Online, and Excel Mobile.

Can I calculate age in months only?
Yes. Use =DATEDIF(A2, B2, "M") to get the total number of complete months between two dates. This is useful for tracking infant age or project timelines.