What I'm trying to do is determine a person's age if I have something like the following: $year = "1964"; $month = "04"; $day = "05"; PHP: Now that I've got these variables, how do I compare them to today's date in order to get the age? I know I'd have to use the date() function somehow, I'm just not sure how.
No, date() is not useful for what you need. mktime [ http://php.net/mktime ] is your friend today. Have a try and let us know if you need more help
try this snippet, i had used it in past.... seems to be working fine for me .. <? $year = "1981"; $month = "04"; $day = "11"; function getdays($day1,$day2) { return round((strtotime($day2)-strtotime($day1))/(24*60*60),0); } $begin = "$year/$month/$day"; $end = date("Y/m/d"); // we set today as an example echo getdays($begin,$end)/365; ?> PHP: cheers
I apologize for bumping this thread, but I need a little more advice and help in this area. I'm using the function above to get the ages, but for some reason it is _sometimes_ off by one year. Is there a timezone that I need to set or is mktime more accurate? How can I get it to output the correct ages?