码迷,mamicode.com
首页 > 其他好文 > 详细

根据当前日期计算年龄

时间:2016-12-27 11:39:20      阅读:245      评论:0      收藏:0      [点我收藏+]

标签:php   计算   lod   int   str   bsp   strtotime   code   年龄   

<?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‘);
?>

根据当前日期计算年龄

标签:php   计算   lod   int   str   bsp   strtotime   code   年龄   

原文地址:http://www.cnblogs.com/lxlry/p/6225249.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!