Page 1 of 1

A very complex birthday problem

Posted: Sat Apr 26, 2003 3:27 pm
by voodoo9055
I been racking my brain over this all week. I have seen plenty of formulas on the net that show you how to calculate someone's age, but not birthdate. I need a formula that will give me the upper bound birthdate and the lower bound birthdate when an age is given. If not birthdate, at least the years.

Posted: Sat Apr 26, 2003 3:59 pm
by volka
The input is "1976" or "03/27/1976" ?

Posted: Sat Apr 26, 2003 4:08 pm
by voodoo9055
For example, let say I know for a fact the person is 26 years old. I want to know the lowest birthdate (or year) and the highest birthdate (or year). I know it is not as simple as subtracting 26 from 2003 which will give you 1977. Some people born in 1976 are now 26 years old too depending on when they where born during the year.

Posted: Sat Apr 26, 2003 4:38 pm
by McGruff
365 days = 31536000s

364 days = 314496000s

So time()+314496000 is 364 days from today; time()-31536000 is 365 days ago.

The date() function lets you format the timestamp any way you like.

The rest is just logic: ie working out how to deal with leap years and adding or subtracting the appropriate number of days from time().

Also remember that February 29th could be a birthdate.