Calculating Age in Excel
Calculating Age in Excel
Calculating Age
You can make use of these numbers in all sorts of ways. You can add a number to a date to give a
date that is a number of days later, or subtract a number to get a date before. You can take one
date from another to find out how many days in between. There are lots of ready-made date
functions too.
NOTE: In older versions of Excel you might get another date. Confused? Don't be. Excel is trying to
help but has misunderstood what we need. In date calculations, the result cell gets automatically
formatted the same way as the first cell in the formula. Because the first cell was formatted as a
date Excel showed you the result as a date, although you wanted to see a number. Just reformat
the cell manually by (in Excel 2003 and older) going to Format > Cells > General or (in Excel
2007 and later) choosing General from the dropdown in the Format section of the Home tab.
We need to convert this number of days into a number of years. Most years have 365 days but
every fourth year has 366 days. So the average number of years is 365.25. Let's modify our
formula (Fig. 3) In this example the formula in cell A3 is =(A1-A2)/365.25
Microsoft Excel
Calculating Age
Note the brackets around the first part of the formula. Brackets mean "Work out this bit first...".
I've used them here to stop Excel trying to divide A2 by 365.25 before taking it away from A1.
Excel formulas do any multiplying and dividing before doing any adding and subtracting, but
anything in brackets gets done first.
Now we can see a number of years, but it's still not quite right. We are getting an accurate result
but we don't really want to see the fraction. As a last refinement we'll wrap the whole thing inside
an INT() function to give us a whole number (an integer). This is better than changing the number
of decimal places displayed, which would risk some numbers being rounded up and giving an
incorrect result. Here's the finished result (Fig. 4). In this example the formula in cell A3 is
=INT((A1-A2)/365.25)
The person was born in 1975. How old are they? You can't say.
The person was born in August 1975. How old are they? You still can't say.
The person was born on 23rd August 1975. How old are they? At last! You have enough
information. You can say for certain.
In order to calculate someone's age precisely you need to know the year in which they were born
and whether or not they have had their birthday. If they have had their birthday you subtract their
birth year from the current year. If they have not yet had their birthday you subtract their birth
Martin Green www.fontstuff.com
Microsoft Excel
Calculating Age
year from the current year, and then subtract 1. Easy! We do it all the time without thinking about
it. But explaining the rules to Excel is a bit more complicated. Here goes...
=IF(MONTH(TODAY())>MONTH(A1),YEAR(TODAY())-YEAR(A1),
IF(AND(MONTH(TODAY())=MONTH(A1),DAY(TODAY())>=DAY(A1)),
YEAR(TODAY())-YEAR(A1),(YEAR(TODAY())-YEAR(A1))-1))
I've written this calculation on three lines for clarity but you should write is as a single expression
without spaces. It assumes that cell A1 contains the person's date of birth. Here's what it says...
IF(MONTH(TODAY())>MONTH(A1)
If this month is later than the month of the persons birthday...
YEAR(TODAY())-YEAR(A1)
...subtract the year in which they were born from this year because they must have had their
birthday.
But what if we haven't passed the month in which they were born. We might be in that month, or
we might not have reached it yet. Let's find out...
IF(AND(MONTH(TODAY())=MONTH(A1),DAY(TODAY())>=DAY(A1))
If we are currently in the month of the person's birthday and it is either their birthday today or we
have passed it...
YEAR(TODAY())-YEAR(A1)
...subtract the year in which they were born from this year because they must have had their
birthday.
But what if this isn't the month in which they were born. We know we haven't passed their birthday
so...
(YEAR(TODAY())-YEAR(A1))-1
...subtract the year in which they were born from this year then subtract 1, because they haven't
had their birthday yet.
Phew!
About IF Functions
An IF function contains three arguments:
IF(Logical Test,Value If True,Value If False)
Logical Test: This is a question or circumstance than can be answered yes or no, or true or false.
Value If True: This is what the function should do if the answer to the test is yes or true.
Value If False: This is what the function should do if the answer to the test is no or false.
In other words, you ask a question. If the answer is yes you do one thing. If the answer is no you
do something else. What the IF function does could be to display a number or piece of text, or it
can do a calculation (which is what is does in the example I've used here).
But what if you don't have a simple yes/no question. The solution is a nested IF function. Instead
of inserting a number, piece of text or calculation, the value if true or value if false part (or both
parts) can be IF functions themselves. They normally need a bit of working out (!) because they
have to use the same logical process as Excel does. If it doesn't work first time, try writing it a
different way. And try "translating" it into English as I did above.
A nested IF function says something like...
"If the answer is yes, do this. If the answer is no do this or this (depending on..."
And if you think the Age Calculator is complicated, consider the fact that from version 2007 on
Excel can handle up to forty-seven (count them!) nested IF functions in a single calculation (older
versions could only manage a mere seven!).