Finding out a person's age in days given their birthday dd/mm/yyyy?

791 Views Asked by At

It has to be somebody alive today. Assume that the day is today - September 15, 2014. This is convenient because the leap years will be regular (once every for years; the weird rule applies to $1900$ but not $2000$)

If I am given somebody's birthday in terms of day $d$, month $m$, and year $y$, is there a mathematical formula in terms of $d, m,$ and $y$ allowing me to find their age?

I would say to generalize the problem to any birth date and any current date, but the leap years would be so irregular I'm not sure it would be possible. However, if it is, by all means..

2

There are 2 best solutions below

0
On

One of the ways you could go about doing this would be to use the floor or ceiling functions to create boolean valued functions out of other mathematical functions, then multiplying those by other mathematical expressions to provide you with your various cases, allowing you to effectively use the same strategy someone writing this in a programming language would use.

For example, $\lfloor cos(\pi n)/2+1\rfloor \times \lfloor \cos(\frac{\pi}{2} n)/2+1 \rfloor$ returns a 1 if n is divisible by 4, and 0 otherwise. Then, you would just have to multiply this function by whatever expression you want to use to handle leap years, plus the negation of this function times whatever expression you want to use to handle on non-leap years.

Of course, it would be more complicated than that, for example, years divisible by 100 are not leap years, but years divisible by 400 are, so you'd have to account for that as well, but it's definitely doable. It won't be the most elegant looking mathematical expression though, unless you're fine with using piecewise defined functions (which would essentially be a form of "if" statement as well, but I'm not sure exactly what your criteria are).

0
On

An one-line equation in which you plug in $d_{1}$, $m_{1}$, $y_{1}$, $d_{2}$, $m_{2}$, and $y_{2}$ to get the time in days from the earlier date to the latter date might be possible, but it wouldn't be pretty.

For example, one piece of information you'd need is how many days into the year is the latter date. Let's assume the latter date is today. As I write this, it's October 30, 2014.

To figure which day of the year October 30 is, I need to add the date ($d_{2}=30$) to the number of days which came before October in this year. To do this purely by an equation, using $m_{2}=1$ for January up to $m_{2}=12$ for December, the math would look like this: $$ d_{2} + (\frac{1}{19958400}((m_{2}-1)(178m_{2}^{10}-12824m_{2}^{9}+406221m_{2}^{8}-7436559m_{2}^{7}+86950965m_{2}^{6}-676958181m_{2}^{5}+3545249204m_{2}^{4}-12298071916m_{2}^{3}+26959705632m_{2}^{2}-33604341120m_{2}+18601228800))) $$ This would yield 30 + 273 = 303, telling me that October 30, 2014 is the 303rd day of the year.

For reference, here's that formula run through Wolfram|Alpha (using $x$ in place of $m_{2}$, and without $d_{2}$ added).

Keep in mind that this formula only accounts for 365-day years, so further adjustment would be needed to account for leap years. Next, we'd need to repeat this equation separately for $d_{1}$, $m_{1}$, and $y_{1}$. We'd also need to account for the number of leap years between the given dates, possibly taking into account the exception for some 00 years.

Such a single-line equation would quickly become complicated. As many computers and languages have character limits on lines, it's not even certain that such a formula would even be useable.

That's why an algorithm is preferred for a problem like this. Break the problem down into individual steps which eventually terminate, and then work through the steps.