function identityToAge($id){
if(empty($id)) return '';
$date=strtotime(substr($id,6,8));
//Get Timestamp of year, month and day of birth
$today=strtotime('today');
//Get today's timestamp
$diff=floor(($today-$date)/86400/365) ;
//Get the approximate number of years between two dates
//Add this number of years to strtotime to get the timestamp of that day and compare it with today’s timestamp
$age=strtotime(substr($ id,6,8).' '.$diff.'years')>$today?($diff 1):$diff;
return $age;
}
The above is the detailed content of Get age based on ID card information. For more information, please follow other related articles on the PHP Chinese website!