Home > Daily Programming > PHP Knowledge > Get age based on ID card information

Get age based on ID card information

XuPing.Yang
Release: 2021-04-25 08:55:45
Original
403 people have browsed it

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!

Related labels:
1
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