Home  >  Article  >  Backend Development  >  php generate age based on date of birth

php generate age based on date of birth

巴扎黑
巴扎黑Original
2016-11-23 15:11:461162browse


$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);


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn