# Why does this age calculation trick work?

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?

• You look much younger in your profile picture. Commented Jul 13, 2015 at 7:10
• @JoonasIlmavirta Lisa Simpson was eight years old back in 1989. That would make her well over 30. Commented Jul 13, 2015 at 7:21
• @Arthur, true, but the picture does give a somewhat younger impression. (I hope we don't need to resort to relativistic arguments explaining how slowly people age in Springfield.) Commented Jul 13, 2015 at 7:30
• yyyymmdd = year*10000 + month*100 + day Commented Jul 13, 2015 at 17:53
• @Arthur Did you use this trick to determine that? Commented Jul 13, 2015 at 18:46

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.

• Thank you for the answer. Also, will it give an answer with even more precision if we include hours, minutes and seconds? Commented Jul 13, 2015 at 19:24
• @RenaeLider Yes it would. That would allow the calculation to work even on your birthday such that if your birth time has passed, it will calculate you to be a year older but not if your birth time has not passed. The current formula will say that you are a year older on your birthday, even if the birth time hasn't passed. Commented Jul 13, 2015 at 19:46

\large\begin{align*} \hphantom{-}(\mathsf{year}_1)(\mathsf{month}_1)(\mathsf{day}_1)\\ -(\mathsf{year}_2)(\mathsf{month}_2)(\mathsf{day}_2) \end{align*} is equal to $$\large\begin{cases} \hphantom{{}-1}(\mathsf{year}_1-\mathsf{year}_2)\Box\Box\Box\Box&\;\textsf{if }(\mathsf{month}_1)(\mathsf{day}_1)\geq (\mathsf{month}_2)(\mathsf{day}_2)\\ (\mathsf{year}_1-\mathsf{year}_2-1)\Box\Box\Box\Box&\;\textsf{if }(\mathsf{month}_1)(\mathsf{day}_1)< (\mathsf{month}_2)(\mathsf{day}_2)\\ \end{cases}$$

• My browser is not rendering all of those characters. Can you find an alternative way to present the special characters? Commented Jul 13, 2015 at 21:27
• @LightnessRacesinOrbit Looking at the markdown I think those boxes are actually deliberate. I'm guessing it's a way of saying "it doesn't matter what's in these places". Commented Jul 13, 2015 at 21:56
• @ChrisHayes: Hmm I see! I'm not an expert on mathematical notation but is this conventional? It confused me somewhat :( Commented Jul 13, 2015 at 22:33
• @LightnessRacesinOrbit I'm no expert myself, so I couldn't say. I don't think questions of this type, where the exact placement of the digits is important but some of those digits can be ignored, come up that often, so it may not be all that standard. Commented Jul 13, 2015 at 22:37
• When writing matrices for example, the symbol $\ast$ is common for unspecified entries.
– quid
Commented Jul 14, 2015 at 11:41

You just have to check two cases, if $mmdd$ of the day you where born is more than current $mmdd$ then the first $4$ digits will be $yyyy-1$. If $mmdd$ of the day you where born is less or eqaul to current $mmdd$ then you get $yyyy$ as answer. Which is correct in both cases.