TeddyKiller Posted April 12, 2010 Share Posted April 12, 2010 How can I do this? The variable for the dob is $dob. Thanks Link to comment https://forums.phpfreaks.com/topic/198273-getting-a-users-age-from-their-date-of-birth/ Share on other sites More sharing options...
TeddyKiller Posted April 12, 2010 Author Share Posted April 12, 2010 I tried this function (see below), but this always returns 40. I figured it's because the DOB in the database isn't a timestamp.. so how could I change this so that it works. function getAge($iTimestamp) { $iDiffYear = date('Y') - date('Y', $iTimestamp); $iDiffMonth = date('n') - date('n', $iTimestamp); $iDiffDay = date('j') - date('j', $iTimestamp); // If birthday has not happen yet for this year, subtract 1. if ($iDiffMonth < 0 || ($iDiffMonth == 0 && $iDiffDay < 0)) { $iDiffYear--; } return $iDiffYear; } Link to comment https://forums.phpfreaks.com/topic/198273-getting-a-users-age-from-their-date-of-birth/#findComment-1040326 Share on other sites More sharing options...
PFMaBiSmAd Posted April 12, 2010 Share Posted April 12, 2010 http://dev.mysql.com/doc/refman/5.0/en/date-calculations.html Link to comment https://forums.phpfreaks.com/topic/198273-getting-a-users-age-from-their-date-of-birth/#findComment-1040330 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.