Jump to content

Calculating Age


karatekid36

Recommended Posts

$now = date("Y");  //year of now
$query = "SELECT DATE_FORMAT(date_column,'%Y') AS birthdate FROM table";
$result = mysql_query($query) or die ("cannot get dates" . mysql_error());
$row = mysql_fetch_assoc($result);
$bdate = $row['birthdate']; //year the person was born

$age = $now - $bdate; //now - year of birth

 

will work for part of the year but needs some maths modfications to make it work for the rest of the year because if i was born in september 1966 I am 40 but because the above will use 2007 and 1966 I will be 41

 

Link to comment
https://forums.phpfreaks.com/topic/59130-calculating-age/#findComment-293697
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.