php instance code for calculating age based on id number

  • 2020-12-19 20:56:01
  • OfStack


<?php
function getAgeByID($id){
       
// It's too much after this year's birthday 1 One full year of life
        if(empty($id)) return '';
        $date=strtotime(substr($id,6,8));
// Gets a timestamp of the 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 the two dates
       
//strtotime Add this number of years and you get the time stamp of that day compared to the time stamp of today
        $age=strtotime(substr($id,6,8).' +'.$diff.'years')>$today?($diff+1):$diff;
 
        return $age;
    }
?>

In addition, the website also provides the following tools for the identification number verification:

http://tools.ofstack.com/bianmin/sfz


Related articles: