SkyRanger Posted April 29, 2007 Share Posted April 29, 2007 I am trying to figure out how to get a visitors age from the date they submitted. I tried a number of things which either a: didn't work or b: had so much code it confused the heck out of me and still didn't work. I tried things like: $bdate = March 31 1972 $age = date('F d Y') - $bdate Tried breaking them down into different parts, but that still didn't work, any help would be greatly apprectiated. So what I am trying todo is say subtract bdate from todays date so for example it would say Age: 35 Or if the bday was May 24 1972 then the age would say Age: 34 Any help would be greatly appreciated. Link to comment https://forums.phpfreaks.com/topic/49203-solved-subtract-dates-to-get-age/ Share on other sites More sharing options...
Barand Posted April 29, 2007 Share Posted April 29, 2007 Subtract year of birth from this year to get age Then compare mmdd of date of birth with mmdd of current date. If birth mmdd is greater, they haven't had their birthday yet this year so decrement age. Link to comment https://forums.phpfreaks.com/topic/49203-solved-subtract-dates-to-get-age/#findComment-241099 Share on other sites More sharing options...
SkyRanger Posted April 29, 2007 Author Share Posted April 29, 2007 Awsome, thanks barand,figured it out. $birthyear = $rowpref['byear']; $birthday = $rowpref['bday']; $birthmonth = $rowpref['bmonth']; $year_diff = date("Y") - $birthyear; $month_diff = date("m") - $birthmonth; $day_diff = date("d") - $birthday; if ($month_diff < 0) $year_diff--; elseif ($month_diff == 0 && $day_diff < 0) $year_diff--; echo $year_diff; Link to comment https://forums.phpfreaks.com/topic/49203-solved-subtract-dates-to-get-age/#findComment-241172 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.