Home > Backend Development > PHP Tutorial > PHP example code to calculate age based on ID number_PHP tutorial

PHP example code to calculate age based on ID number_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 10:40:42
Original
1172 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...
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template