A very complex birthday problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
voodoo9055
Forum Commoner
Posts: 51
Joined: Sat Apr 26, 2003 3:27 pm
Location: Montgomery, AL

A very complex birthday problem

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

The input is "1976" or "03/27/1976" ?
User avatar
voodoo9055
Forum Commoner
Posts: 51
Joined: Sat Apr 26, 2003 3:27 pm
Location: Montgomery, AL

Post 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.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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.
Post Reply