jesushax Posted April 14, 2009 Share Posted April 14, 2009 hi all, what im trying to find out how to do is from a year eg, 1985 a script to work out that that person is 24 anyone know how? thanks Link to comment https://forums.phpfreaks.com/topic/153986-solved-work-out-age-given-a-year/ Share on other sites More sharing options...
jesushax Posted April 14, 2009 Author Share Posted April 14, 2009 done it <?php $CurrentYear = date("Y"); $StartYear = 1985; $CompanyAge = $CurrentYear - $StartYear; echo $CompanyAge; ?> Link to comment https://forums.phpfreaks.com/topic/153986-solved-work-out-age-given-a-year/#findComment-809389 Share on other sites More sharing options...
PFMaBiSmAd Posted April 14, 2009 Share Posted April 14, 2009 You will find that will only work when the birthday has already occured in the current year. You must subtract 1 if the birthday has not already occured in the current year - <?php $date = '1985-04-14'; // standard yyyy-mm-dd format $today = date("Y-m-d"); $age = substr($today, 0, 4) - substr($date, 0, 4) - (substr($today, 5,5) < substr($date, 5,5)); echo "DOB: $date, Age: $age<br />"; ?> Link to comment https://forums.phpfreaks.com/topic/153986-solved-work-out-age-given-a-year/#findComment-809685 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.