Age calculation excel formula?
In this article
To calculate age in Excel, use the DATEDIF function with the syntax =DATEDIF(start_date, end_date, "Y"). This formula returns the complete number of years between two dates, making it ideal for calculating a person's age based on their date of birth.
Background on Date Functions in Excel
Excel stores dates as serial numbers, where January 1, 1900, is serial number 1, and each subsequent day increments by one. This internal system allows Excel to perform arithmetic and comparisons on dates. While Excel has many date-related functions—such as TODAY(), DATE(), YEAR(), MONTH(), and DAY()—none directly calculate age in full years. That’s where the DATEDIF function comes in, despite being undocumented by Microsoft in modern versions.
The DATEDIF function has been available since Lotus 1-2-3 compatibility days and remains functional in all current versions of Excel, including Microsoft 365. Although it doesn't appear in the function wizard or IntelliSense, it works reliably when typed manually. This has led to confusion among users who assume it's deprecated or unreliable, but it is in fact the most accurate method for calculating age in years.
How the DATEDIF Formula Works
The DATEDIF function calculates the difference between two dates in years, months, or days, depending on the unit specified. For age calculation, the "Y" unit is used to return the number of complete years.
Syntax:
- =DATEDIF(start_date, end_date, "Y")
Where:
- start_date is the earlier date (e.g., date of birth)
- end_date is the later date (e.g., today’s date or a specific reference date)
- "Y" specifies that the result should be in complete years
Example: If cell A1 contains a birthdate of January 15, 1990, and you want to calculate age as of today:
- =DATEDIF(A1, TODAY(), "Y")
This returns 34 (as of 2024), representing the full years elapsed since birth.
Alternative Methods and Their Limitations
Because DATEDIF is not officially documented, users often attempt alternative formulas, but these come with drawbacks:
- Using YEARFRAC and INT: =INT(YEARFRAC(A1, TODAY())) — This calculates the fraction of the year between two dates and truncates it. However, it can round incorrectly near birthdays due to how leap years and partial months are interpreted.
- Using YEAR alone: =YEAR(TODAY()) - YEAR(A1) — This only compares the year numbers and ignores month and day, so someone born in December 2000 would be counted as 24 in January 2024, even if their birthday hasn’t occurred yet.
- Manual calculation with MONTH and DAY: Complex nested IF statements can adjust for whether the birthday has occurred this year, but they are error-prone and harder to maintain.
The DATEDIF function avoids these issues by internally checking whether the end date has passed the anniversary of the start date in the current year.
Common Problems and How to Fix Them
Users often encounter errors when working with age calculations in Excel. Here are frequent issues and solutions:
- #NUM! error: Occurs if the start_date is later than the end_date. Ensure the birthdate is earlier than the comparison date.
- #VALUE! error: Happens when one of the date inputs is not a valid date. Use DATE(YYYY, MM, DD) or ensure cells are formatted as dates.
- Incorrect age by one year: Often due to using YEAR alone instead of DATEDIF. Always use "Y" unit for accurate full-year differences.
- Display issues: If the result shows as a date (e.g., 1/5/1900), change the cell format to General or Number.
Always validate your formula with known date pairs. For example, a person born on June 15, 2000, should be 23 years old on June 14, 2024, and 24 on June 15, 2024. Test your formula around these dates to confirm accuracy.
Advanced Age Calculations: Years, Months, and Days
You can extend the DATEDIF function to show age in years, months, and days for greater detail. For example:
- Years: =DATEDIF(A1, TODAY(), "Y")
- Months after years: =DATEDIF(A1, TODAY(), "YM") — gives months after the last complete year
- Days after months: =DATEDIF(A1, TODAY(), "MD") — gives days after the last complete month
To combine them in one cell:
=DATEDIF(A1,TODAY(),"Y")&" years, "&DATEDIF(A1,TODAY(),"YM")&" months, "&DATEDIF(A1,TODAY(),"MD")&" days"
This returns a string like "34 years, 5 months, 10 days". Note: "MD" can be inaccurate in some edge cases (e.g., when end date is the last day of the month), so verify results manually if precision is critical.
Frequently Asked Questions
Why doesn’t DATEDIF show up in Excel’s function list?
DATEDIF is a legacy function retained for compatibility with older spreadsheets, particularly from Lotus 1-2-3. Microsoft does not promote it due to a few known edge-case bugs in specific unit combinations, but it is safe and accurate when using the "Y", "M", and "D" units for age calculation.
Can I calculate age on a specific date, not today?
Yes. Replace TODAY() with a fixed date. For example, to calculate age on December 31, 2023: =DATEDIF(A1, DATE(2023,12,31), "Y"). This is useful for historical data or projections.
What if I only have the birth year, not the full date?
If only the year is known, you can estimate age using =YEAR(TODAY()) - birth_year. However, this may be off by one year depending on the current month. It’s less accurate than using a full birthdate with DATEDIF.
Does DATEDIF account for leap years?
Yes. Because DATEDIF calculates based on actual calendar dates, it correctly handles leap years. A person born on February 29 will have their birthday counted on February 28 or March 1 in non-leap years, and DATEDIF reflects this accurately.
Can I use DATEDIF in Google Sheets?
Yes. Google Sheets fully supports the DATEDIF function with the same syntax and behavior as Excel. It’s also not in the function browser but works when typed manually.
How do I calculate age in months or days?
Use =DATEDIF(A1, TODAY(), "M") for total months or =DATEDIF(A1, TODAY(), "D") for total days. These return complete months or days between the dates, useful for infant age or project durations.