|
It's definitely not as easy as it sounds.
Say you were given somebody's birthday. The year, the month, and the day. For our example we will use 1970/05/05 (May 5th, 1980).
Now we take today's date, 2011/02/21 (Feb 21st, 2011).
What I've done is removed the slashes, and then subtracted today's date from the user's birthday, with a decimal after the year. Example:
2011.0221 - 1970.0505
The result given is not correct, however. This is because of leap years, and months having a different number of days.
How could I calculate an age when given a birthday?
I have also tried converting the string to base12, and then subtracting, but it's still off.
I've thought about it, and come up with a solution. Does PHP have any sort of time function (I know of strtotime), one that could calculate this sort of thing?
Thanks!!
|