时时商务社区

标题: PHP 年龄计算函数(精确到天) [打印本页]

作者: bewin83    时间: 2018-2-14 08:28

            [U]复制代码[/U] 代码如下:
'2000',
'month' => '11',
'day' => '3'
);
$birthStr = '2000-11-03';
* --------------------------------------------------
* );
* @author IT不倒翁
* @copyright (c) 2011,2012 Just Use It!
* @link IT不倒翁 http://yungbo.com
* @param string|array $birthday
* @return number $age
*/
function getAge($birthday) {
$age = 0;
$year = $month = $day = 0;
if (is_array($birthday)) {
extract($birthday);
} else {
if (strpos($birthday, '-') !== false) {
list($year, $month, $day) = explode('-', $birthday);
$day = substr($day, 0, 2); //get the first two chars in case of '2000-11-03 12:12:00'
}
}
$age = date('Y') - $year;
if (date('m')
            
            
您可能感兴趣的文章:
  • 计算一段日期内的周末天数的php代码(星期六,星期日总和)
  • 在php和MySql中计算时间差的方法
  • 如何使用PHP计算上一个月的今天
  • php根据身份证号码计算年龄的实例代码
  • php计算几分钟前、几小时前、几天前的几个函数、类分享
  • PHP中UNIX时间戳和日期间的转换与计算实例
  • php计算两个日期相差天数的方法
  • php根据生日计算年龄的方法
  • php计算年龄精准到年月日
  • php简单计算年龄的方法(周岁与虚岁)
            




    欢迎光临 时时商务社区 (http://bbs.4435.cn/) Powered by Discuz! X3.2