php 根據出生日期生成年齡

<?php

$birthday = '1985-02-01';
$age = date('Y', time()) - date('Y', strtotime($birthday)) - 1;
if (date('m', time()) == date('m', strtotime($birthday))){

	if (date('d', time()) > date('d', strtotime($birthday))){
	$age++;
	}
}elseif (date('m', time()) > date('m', strtotime($birthday))){
	$age++;
}
echo $age;


?>


mysql 當前時間-n年計算
select date_add(curdate(), interval -1 year);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章