PDA

View Full Version : Age calculation with PHP


Benson
04-08-2002, 01:19 PM
I found this little bit of PHP code that will display a person's age in a web page. How can I change it so that the result will be "12" instead of "12.02345"?



<?php
$dofb = strtotime ("2 November 1980"); // date to calculate from
$age = strtotime ("now")-$dofb;
$age_in_years = $age/31557600; // 31557600 seconds in a year
echo "$age_in_years";
?>

Benson
04-08-2002, 01:32 PM
I found it (yea!)


<?php
$dofb = strtotime ("2 November 1980"); // date to calculate from
$age = strtotime ("now")-$dofb;
$age_in_years = $age/31557600; // 31557600 seconds in a year
$current_age = floor($age_in_years);
echo "$current_age";

?>