If you handle employee-related matters in your office, you might need to determine the age of employees based on their birthdates. In this tutorial, you will learn both non-array and array formulas for calculating age from birthdates (DOB) in Google Sheets.
Calculating Age from Birthdates: Years Only
If cell A1 contains the date of birth, for example, 31/12/2000, you can use the following formula to calculate the age in years:
=DATEDIF(A1, TODAY(), "Y")
This formula follows the syntax of DATEDIF(start_date, end_date, unit)
, where start_date
is the date of birth in cell A1, end_date
is today’s date, and unit
is “Y,” representing the number of whole years between start_date
and end_date
.
The above formula is commonly used to find age from the date of birth (DOB) in Google Sheets.
Ref.: How to Utilise Google Sheets Date Functions [Complete Guide]
Extracting Years from DOB in a Column
If you have dates in column A and want to extract the age, you can use the above formula in cell B1 and drag the fill handle of cell B1 down (copy-paste the formula down).
But you can use an array formula as well which will spill the results down.
=ArrayFormula(IFERROR(DATEDIF(DATEVALUE(A1:A), TODAY(), "Y")))
This covers the whole column. But you can limit the expansion up to a specific number of rows by replacing A1:A with a range like A1:A100.
The above is an array formula to return age from the date of birth in Google Sheets.
You may wonder why I don’t simply use:
=ArrayFormula(DATEDIF(A1:A, TODAY(), "Y"))
The reason is it will consider blank cells as 0, which is equal to the date 30/12/1899. So it returns the difference between 30/12/1899 and today’s date.
The DATEVALUE function converts valid dates to date values and returns errors in all other cells. The IFERROR function removes those errors after age calculation.
Calculating Full Age in Years, Months, and Days in Google Sheets
To calculate full age, you need to extract the years, months, and days from the date of birth. We can use the DATEDIF function for that.
Assume the DOB is in cell A1. The following formula will return the age in years, months, and days in three individual cells:
=ArrayFormula(DATEDIF(A1, TODAY(), {"Y", "YM", "MD"}))
31/01/2000 | 24 | 1 | 27 |
The unit
in the DATEDIF function contains multiple units such as an array {"Y","YM", "MD"}
. So I used the ArrayFormula function.
Where:
- Y: the number of whole years between DOB and today’s date.
- YM: the number of whole months between DOB and today’s date after subtracting whole years.
- MD: the number of days between DOB and today’s date after subtracting whole months.
If you want it in the format “n years, n months, and n days“, use the following formula:
=LET(
f_a, ArrayFormula(DATEDIF(A1, TODAY(), {"Y","YM", "MD"})),
y_, CHOOSECOLS(f_a, 1),
m_, CHOOSECOLS(f_a, 2),
d_, CHOOSECOLS(f_a, 3),
IF(y_>1, y_&" years, ", y_&" year, ") &
IF(m_>1, m_&" months, and ", m_&" month, and ") &
IF(d_>1, d_&" days ", d_&" day ")
)
Formula Explanation:
The formula ArrayFormula(DATEDIF(A1, TODAY(), {"Y","YM", "MD"}))
returns the age in years, months, and days in individual cells (an array result). We use the LET function to name it as f_a
.
The CHOOSECOLS function extracts the years, months, and days from f_a
, and their assigned names are y_
, m_
, and d_
, respectively, using LET.
The IF function evaluates whether the results are a single year, month, or day and assigns the texts “year” or “years”, “month” or “months”, and “day” or “days” accordingly. It then combines the corresponding values (y_, m_, d_
) with these texts. Each evaluation is combined, resulting in the final result.
Extracting Full Age from DOB in a Column
To get the years, months, and days in three separate columns, use this formula:
=ArrayFormula(IFERROR(DATEDIF(DATEVALUE(A1:A), TODAY(), {"Y", "YM", "MD"})))
If you enter it in cell B1, it will extract the age in years, months, and days from the range A1:A and spill the results into columns B, C, and D.
If you want it in combined form, use this one:
=ArrayFormula(LET(
f_a, DATEDIF(A1:A, TODAY(), {"Y","YM", "MD"}),
y_, CHOOSECOLS(f_a, 1),
m_, CHOOSECOLS(f_a, 2),
d_, CHOOSECOLS(f_a, 3),
dob,
IF(y_>1, y_&" years, ", y_&" year, ") &
IF(m_>1, m_&" months, and ", m_&" month, and ") &
IF(d_>1, d_&" days ", d_&" day "),
IF(A1:A="", , DOB)
))
Just wondering if there is a way to leave the ‘age’ cell blank if there is no data in the date of the birth column for that row?
Thanks.
There are several ways to achieve this.
Just use LEN function with IF to return the age as blank, if there is no date in the DOB cell.
See how to use LEN with different formulas returning age from date.
=if(len(A1),int(YEARFRAC(A1,today())),)
In a date column, use the array formula.
=ArrayFormula(if(len(A3:A),int(yearfrac(A3:A,today(),1)),))
Here is another one.
=if(len(A1),datedif(A1,today(),"Y")&" Years "&datedif(A1,today(),"YM")&" months & "& datedif(A1,today(),"MD")&" days",)
Best,
Hi,
I’m getting this response in some of the cells, but not others.
Error
“Function DATEDIF parameter 1 expects number values. But ’18/07/1997′ is a text and cannot be coerced to a number.”
Can you suggest how I fix this? Thank you.
Hi, Andrew,
You can check that cell with the ISDATE function.
You should follow the date format on your Sheet. It may be in DD/MM/YYYY or MM/DD/YYYY format by default. This setting is inherited from the Locale settings in your Google Sheets File menu, Spreadsheet settings.
So follow that format in your date entries.
Best,