根据当前日期计算年龄

废话不多说,直接上代码

<?php
function birthday($birthday){
 $age = strtotime($birthday);
 if($age === false){
  return false;
 }
 list($y1,$m1,$d1) = explode("-",date("Y-m-d",$age));
 $now = strtotime("now");
 list($y2,$m2,$d2) = explode("-",date("Y-m-d",$now));
 $age = $y2 - $y1;
 if((int)($m2.$d2) < (int)($m1.$d1))
  $age -= 1;
 return $age;
}
echo birthday('1986-07-22');
?>

 

posted on 2016-12-27 11:30  lxlry  阅读(370)  评论(0编辑  收藏  举报

导航