PHP example code to calculate age based on ID number_PHP tutorial

WBOY
Release: 2016-07-13 10:40:42
Original
1059 people have browsed it

Copy code The code is as follows:

function getAgeByID($id){

/ / Only after this year’s birthday is one more year old
If(empty($id)) return '';
$date=strtotime(substr($id,6,8));
// Get the time stamp of the date of birth
$ TODAY = StrTotime ('TODAY');
// Get today's timestamp
$ Diff = Floor (($ today-$ date)/86400 /365);
//Get the approximate number of years between the two dates

//Add this number of years to strtotime to get the timestamp of that day and compare it with today’s timestamp
       =strtotime(substr($id,6,8).' +'.$diff.'years')>$today?($diff+1):$diff;

Return $age;
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/714950.htmlTechArticleCopy the code as follows: ?php function getAgeByID($id){ //It’s only after this year’s birthday 1 more year old if(empty($id)) return ''; $date=strtotime(substr($id,6,8)); //Get the date of birth...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!