BrianM Posted July 15, 2008 Share Posted July 15, 2008 Does anyone know of a tutorial showing how this is done, or does anyone mind explaining? Link to comment https://forums.phpfreaks.com/topic/114785-calculate-age-using-php-based-upon-dob/ Share on other sites More sharing options...
DeanWhitehouse Posted July 15, 2008 Share Posted July 15, 2008 look in the maths section Link to comment https://forums.phpfreaks.com/topic/114785-calculate-age-using-php-based-upon-dob/#findComment-590183 Share on other sites More sharing options...
d.shankar Posted July 15, 2008 Share Posted July 15, 2008 i have given a simple example....... <?php $dob=1984; #Input you year of birth $today=date('Y'); $age=$today-$dob; echo $age; ?> Link to comment https://forums.phpfreaks.com/topic/114785-calculate-age-using-php-based-upon-dob/#findComment-590198 Share on other sites More sharing options...
corbin Posted July 15, 2008 Share Posted July 15, 2008 d.shankar, that could be wrong depending on the months. @OP look at http://www.phpfreaks.com/forums/index.php/topic,205003.0.html (My solution is not the best by the way) Link to comment https://forums.phpfreaks.com/topic/114785-calculate-age-using-php-based-upon-dob/#findComment-590203 Share on other sites More sharing options...
d.shankar Posted July 15, 2008 Share Posted July 15, 2008 Yes i agree corbin... i havent framed a 100% solution though... Just to give brian a start. Link to comment https://forums.phpfreaks.com/topic/114785-calculate-age-using-php-based-upon-dob/#findComment-590206 Share on other sites More sharing options...
samshel Posted July 15, 2008 Share Posted July 15, 2008 <?php $dtBirthDate = "1978-09-13"; $dtToday = date("Y-m-d"); //Calculate difference in seconds $intDiffSec = strtotime($dtToday) - strtotime($dtBirthDate); //Calculate no of days $intDays = $intDiffSec / (60*60*24); $intYearsAge = (int) ($intDays / 365); $intDaysAge = $intDays - ($intYearsAge * 365); echo "Age is : ".$intYearsAge. " Years and ".$intDaysAge." Days" ; ?> something like this should also work...not tested. PS: Leap years are not considered... Link to comment https://forums.phpfreaks.com/topic/114785-calculate-age-using-php-based-upon-dob/#findComment-590209 Share on other sites More sharing options...
JasonLewis Posted July 15, 2008 Share Posted July 15, 2008 Here is how I did it for my forum: $birthMonth = 4; $birthDay = 24; $birthYear = 1946; if($birthYear > date("n")){ $age = (date("Y") - $birthYear); //you have turned your age because your birthmonth is greater then the current month }else{ //your birthmonth is less then the current month //Now check if the month we are in is the same as your month... if($birthMonth == date("n") && $birthDay < date("d")){ //It's the same month, but the current day is greater then your actual birth day... $age = (date("Y") - $birthYear)-1; //havnt turned your age this year so take 1 away from age }else{ //You must've had your birthday... $age = (date("Y") - $birthYear); //turned your age this year } } Link to comment https://forums.phpfreaks.com/topic/114785-calculate-age-using-php-based-upon-dob/#findComment-590225 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.