Age calculation from dob in excel formula?
In this article
To calculate age from a date of birth (DOB) in Excel, use the DATEDIF function: =DATEDIF(A2, TODAY(), "Y"). This returns the complete number of years between the DOB in cell A2 and today's date. For more precision, including months and days, additional DATEDIF arguments can be combined.
Background and Why Accurate Age Calculation Matters
Calculating age from a date of birth is a common task in HR, healthcare, education, and personal record-keeping. While it may seem simple—subtract the birth year from the current year—doing so without considering the exact month and day can result in incorrect age values. For example, someone born in December 2000 is not the same age in January 2024 as someone born in March 2000, even though both share the same birth year. Excel's date system allows for precise arithmetic, but using basic subtraction can misrepresent age by up to a year.
Excel stores dates as serial numbers, where January 1, 1900 is 1, and each subsequent day increments by 1. This system enables robust date math. However, because age is typically expressed in whole years and must account for whether the birthday has occurred this year, a simple YEAR(TODAY()) - YEAR(A2) formula is unreliable. The DATEDIF function, though undocumented by Microsoft in modern Excel versions, remains the most accurate method for calculating full years between two dates.
How the DATEDIF Function Works
The DATEDIF function calculates the difference between two dates in years, months, or days. Despite being hidden from the function library and lacking IntelliSense support in newer Excel versions, it is fully functional and widely used for age calculation.
Syntax: DATEDIF(start_date, end_date, unit)
- start_date: The earlier date (e.g., date of birth)
- end_date: The later date (e.g., TODAY() or a specific date)
- unit: A text string specifying the time unit to return
Common units include:
"Y"– Complete years"M"– Complete months"D"– Total days"YM"– Months after subtracting full years"YD"– Days after subtracting full years (assumes same year)"MD"– Days after subtracting full months (use with caution due to leap year edge cases)
For age in full years: =DATEDIF(A2, TODAY(), "Y")
Building a Complete Age Display
For a full age breakdown (years, months, and days), combine multiple DATEDIF calls:
- Years:
DATEDIF(A2, TODAY(), "Y") - Months:
DATEDIF(A2, TODAY(), "YM") - Days:
DATEDIF(A2, TODAY(), "MD")
To display all in one cell:
=DATEDIF(A2,TODAY(),"Y")&" years, "&DATEDIF(A2,TODAY(),"YM")&" months, "&DATEDIF(A2,TODAY(),"MD")&" days"
This formula returns a text string like "34 years, 6 months, 12 days". Note that "MD" can occasionally return negative values in rare leap year scenarios, so use it cautiously for critical applications.
Alternatives to DATEDIF
Because DATEDIF is undocumented, some users prefer alternative methods.
- YEARFRAC function:
=INT(YEARFRAC(A2, TODAY()))returns the number of complete years. It uses a fraction of the year based on day count and is more transparent than DATEDIF. - Date arithmetic with INT:
=INT((TODAY()-A2)/365.25)approximates age using average year length. However, this is less accurate over long periods and can be off by a year near birthdays. - Using FLOOR and YEAR:
=FLOOR(YEARFRAC(A2, TODAY(), 1), 1)is a robust alternative that accounts for actual calendar days.
While these alternatives work, DATEDIF remains the most precise for whole-year age calculation because it explicitly counts completed calendar years.
Common Problems and How to Avoid Them
Several issues arise when calculating age in Excel:
- Invalid date formats: If DOB is entered as text (e.g., "12/3/1990" not recognized as a date), formulas fail. Use
ISDATE(A2)or check cell formatting. - Future dates: If the DOB is after TODAY(), DATEDIF returns a #NUM! error. Wrap with IF:
=IF(A2>TODAY(), "Future date", DATEDIF(A2,TODAY(),"Y")). - Empty cells: Blank DOB fields cause errors. Use:
=IF(ISBLANK(A2), "", DATEDIF(A2,TODAY(),"Y")). - Leap year edge cases: DATEDIF correctly handles leap years, but manual calculations using 365.25 can drift over decades.
- Time components: If dates include time (e.g., 12:30 PM), ensure consistency. Use
INT(A2)to strip time if needed.
Accuracy and Limitations
DATEDIF is accurate for civil date calculations and aligns with how most organizations define age—based on completed calendar years. However, it assumes the Gregorian calendar and does not account for time zones or birth times. For medical or legal applications requiring hour-level precision, additional time data is needed.
The function does not support negative ages or dates before January 1, 1900 (Excel's default date system limit). For dates before 1900, consider using the 1904 date system (Mac legacy) or external tools. Also, DATEDIF may behave unexpectedly with dates in the far future due to Excel's maximum date limit (December 31, 9999).
For auditing or compliance, always validate age calculations with known test cases (e.g., a person born January 1, 2000, should be 24 on January 1, 2024).
Frequently Asked Questions
Why doesn't DATEDIF show up in Excel's function list?
DATEDIF is a legacy function from Lotus 1-2-3, retained in Excel for backward compatibility. Microsoft does not actively promote it, but it remains fully functional and safe to use.
Can I calculate age on a specific date, not today?
Yes. Replace TODAY() with a fixed date: =DATEDIF(A2, DATE(2025,6,15), "Y") calculates age on June 15, 2025.
What if I need age in months for infants?
Use =DATEDIF(A2, TODAY(), "M") for total completed months. For years and months: =DATEDIF(A2,TODAY(),"Y")&" years, "&DATEDIF(A2,TODAY(),"YM")&" months".
Is YEARFRAC more accurate than DATEDIF?
YEARFRAC calculates fractional years based on day count (e.g., 365 or 366-day years), which can be useful for financial or scientific contexts. For whole-year age, DATEDIF is more appropriate as it reflects completed calendar years.
Why does DATEDIF with "MD" sometimes give wrong days?
The "MD" unit calculates days between dates after subtracting whole months. It can fail in edge cases (e.g., from January 31 to February 28). Avoid "MD" for critical calculations; use "YD" or manual day logic instead.
Can I calculate age in Excel Online or Google Sheets?
Yes. DATEDIF works identically in Excel Online, Google Sheets, and desktop Excel. The syntax and behavior are consistent across platforms.