[Math] Why does this age calculation trick work

arithmeticcalendar-computationspuzzle

The trick works like this: Take the current date in the format yyyymmdd and subtract it with your date of birth taken in the same format. Drop the last four digits to get your age.

For example, I was born in August 20th, 1994. Today it is July 13th, 2015.

$$
20150713 – 19940820 = 209893\\
\textrm{Dropping the last four digits,}\\
\textrm{My age}=20
$$

I can understand subtracting two years, but how does crafting these numbers with month and day make it more accurate?

Best Answer

Subtracting the month and day lets you take into account whether you've had your birthday this year. If you have had your birthday, then you can just skip the month and day, they don't affect the two years at all (do the subtraction by hand to see this more clearly). If you haven't had your birthday yet, then the process of borrowing will subtract a year for you.

Related Question