Calculating age in spreadsheet

Hi,

Does anybody know a way to have somebody's age calculated in a field in a spreadsheet, after manual input of the date of birth in another field? The age should also be automatically recalculated everytime the sheet is opened.

I have tried a lot of formulas but has been not successfull so far...

Thanks,
Maarten

iMac 2.4GHz Intel Core 2 Duo, Mac OS X (10.5.1)

Posted on Feb 5, 2008 3:14 PM

Reply
10 replies

Feb 5, 2008 3:46 PM in response to Maarmarg

Hi Maarten,

Calculating age is very simple, provided you want to express the answer in the Mac clock's basic unit, the Day.

With the birthdate in cell A1, enter this formula in the cell you want to display the age:

=INT(NOW())-A1

NOW() returns a serial number indicating the current time (in Days and fraction of Day) according to the Mac's clock at the instant the formula was called. For example, at 3:32:04 PM on Feb 5, 2008, NOW() returned 38021.647269. INT() strips the fractional part (which represents the time of day), leaving only the whole number (date) part.

Converting that result from Days to Years, Years and Months, or Years, Months and Days requires dealing with the vagaries of the calendar. More on that to follow.

Regards,
Barry

Feb 5, 2008 4:24 PM in response to Maarmarg

More...

Maarten wants to calculate the age as of 'today'. Others may want the age on a specific date. To handle both these cases, I'll put the 'as of' date in cell A1, and reference that cell in formulas. Date of Birth (DOB) will be recorded in column A, starting at A3.


Enter =NOW() in cell A1 (for calculation of age as of 'today') OR Enter a specific 'as of' date in B1

Enter the (first) DOB in cell A3.

_Calculation of age in years._

Enter the following formula in B3:

=IF(A3,YEAR(A$1)-YEAR(A3)-((31 MONTH(A3)DAY(A3))>(31MONTH(ADAY(A3))>(31MONTH(A$1))DAY(A$1))),"")

--The IF statement keeps the cell containing the formula blank until something is entered in cell A3.
--The part between the commas calculates the age in years by first subtracting the YEAR extracted from the DOB from the YEAR extracted from A1, then applies a correction, subtracting 1 if the current date is before the anniversary of the birth in the current year.

_Caclulation of additional months_

Enter the following in C3:

=IF(A3,MONTH(A$1)-MONTH(A3)+12*((MONTH(A$1)-MONTH(A3))<0)-(DAY(A$1)<DAY(A3)),"")

--The IF statement performs the same function as above.
--The part between the commas calculates the remaining months of the age by first subtracting the MONTH extracted from the DOB from the MONTH extracted from A1, then applies two corrections, first increasing the value by 12 if the initial result in negative, then subtracting 1 if the 'as of' day of the month is less than the day of the month of the DOB.

Regards,
Barry

Feb 6, 2008 12:27 PM in response to Barry

Hi Barry,

First of all, let me thank you for your very detailed answer. It is far more than one usually might expect on forums. So thanks again for that.

That being said, I hate to say, that I am still not able to calculate an age in my sheet.
I followed your guidelines, but the large formula for a "calculation of age in years" gives an error on enter (formula appears in field in sheet). I do had to translate your formula into Dutch as I use the Dutch version of AW. But in my opinion, that should not be the problem, as english words like "DAY", YEAR" or MONTH" are not very difficult to translate....

I have changed and deleted some parts of the formula, to see if something might work and I finally I got a result from this formula:

=JAAR(A1)-JAAR(A3)-(31 MAAND(A3)DAG(A3))>(31MAAND(A1)DAG(A1))

The result of the formula is "untrue" (in Dutch)

Any suggestions?

Thanks in advance,

Maarten

P.s.: I was also wondering about the "$"-sign in the formula, as I am not familiar with that being used in AW? I am pretty new with AW, as you have probably noticed by now..:-(

Feb 6, 2008 8:23 PM in response to Maarmarg

Hi Maarten,

_Formula troubleshooting_:

A TRUE or FALSE result result means the formula is comparing two values and returning the result of the comparison.

In the formula you came up with, the only comparison operator is the ">" sign, so the formula must be comparing what's in front of that to what follows it.

=JAAR(A1)-JAAR(A3)-(31*MAAND(A3)+DAG(A3)) > (31*MAAND(A1)+DAG(A1))

What the formula should be doing is two subtractions. First subtracting the second term ( JAAR(A3) ) from the first ( JAAR(A1) ), then subtracting the result of the comparison in the rest of the formula.
Here's your revision and my original (with the IF() statement removed). I've added some spaces to yours to make the terms line up a bit better.

=JAAR(A1)-JAAR(A3) - (31 MAAND(A3)DAG(A3))>(31MAAND(A1)DAG(A1))
=YEAR(A$1)-YEAR(A3)-((31 MONTH(A3)DAY(A3))>(31MONTH(ADAY(A3))>(31MONTH(A$1))DAY(A$1)))

The only difference (other than the $, discussed below) is a pair of brackets around everything following the second "-" sign. Those brackets limit the comparison to what's between them, and make the result of that comparison (which will be either 1—TRUE— or 0—FALSE) the amount to be subtracted from the previous part of the formula.

The function of the "$" sign in the formula is to fix the cell reference to a specific column or row.

In this case, I've assumed you'll have a list of birthdates (in A3, A4, A5, etc.) and a single date (in A1) on which you want to calculate all of the ages.

After you've entered the formula into B3, you can copy it into the rest of the cells in column B using Fill Down (Select the cells to contain the formula, including B3, then go Calculate > Fill Down).

Without the $, the A3 cell references in the initial formula will be changed to reference a cell in the same relative position with respect to the formula's 'new' location.

Example: in B3: =A3
Fill down to B5: =A5

The $, placed before the row reference fixes that reference to the initial row.

Example: in B3: =A$1
Fill down to B5: =A$1

Placed in front of the column reference ($A1) the $ fixes the column when a formula is filled right.
Placed in front of both column and row references ($A$1), the cell reference remains fixed when the formula is filled down or right.

Regards,
Barry

Feb 7, 2008 12:54 AM in response to Maarmarg

Thanks again, Barry, for your patience and time. Really appreciate it.

I have changed the formula, and it works fine now. Only thing still failing at this moment, is if I add the "IF"-part from your formula. The full formula looks exactly the same as yours, but does not seem to be working, still giving an error on enter (formula appears in field in sheet).

=ALS(A3,JAAR(A$1)-JAAR(A3)-((31 MAAND(A3)DAG(A3))>(31MAAND(ADAG(A3))>(31MAAND(A$1))DAG(A$1))),"")

I understand, the "IF" part is for when A3 is empty, it puts whatever is between "" in the field?

Maarten

Feb 7, 2008 7:35 AM in response to Maarmarg

Hello

I think you use comma for decimal separator in Netherlands, in which case you should use semicolon for argument delimiter in AppleWorks' functions.

E.g.

=ALS(A3;JAAR(A$1)-JAAR(A3)-((31 MAAND(A3)DAG(A3))>(31MAAND(ADAG(A3))>(31MAAND(A$1))DAG(A$1)));"")

Please see AW's help for details of function syntax in your language.
Hope this helps,
H

Feb 7, 2008 7:49 AM in response to Maarmarg

Hello

it seems that you didn't take care that the decimal separator in your country is not the period but the comma.
So the operand delimiter is not the comma but the semi-colon.

May I tell you that I am really surprised that you didn't realize that the delimiters used by Barry aren't those used in your country.

May you try:

in B3 =ALS(A3;JAAR(A$1)-JAAR(A3)-((31 MAAND(A3)DAG(A3))>(31MAAND(ADAG(A3))>(31MAAND(A$1))DAG(A$1)));"")

in C3 =ALS(A3;MAAND(A$1)-MAAND(A3)+12*((MAAND(A$1)-MAAND(A3))<0)-(DAG(A$1)<DAG(A3));" ")

No, I don't know Dutch, I just installed the Dutch localized version and asked it to open the sheet built in English 😉

Yvan KOENIG (from FRANCE jeudi 7 février 2008 16:45:16)

Hello HIROTO

Glad to meet you here.

I arrived some minutes late but I have the two formulas 😉

Message was edited by: KOENIG Yvan

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Calculating age in spreadsheet

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.