【php开源代码栏目提醒】:网学会员在php开源代码频道为大家收集整理了calc_age.php提供大家参考,希望对大家有所帮助!
<?php
// set date for calculation
$day = 18;
$month = 9;
$year = 1972;
// remember you need bday as day month and year
$bdayunix = mktime ('', '', '', $month, $day, $year); // get ts for then
$nowunix = time(); // get unix ts for today
$ageunix = $nowunix - $bdayunix; // work out the difference
$age = floor($ageunix / (365 * 24 * 60 * 60)); // convert from seconds to years
echo "Age is $age";
?>