Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function deciderlab_calc_age_from_idcode($idcode)
- {
- if(strlen($idcode) != 11 || !is_numeric($idcode)) {
- return false;
- }
- $century = substr($idcode, 0, 1);
- $year = substr($idcode, 1, 2);
- $month = intval(substr($idcode, 3, 2));
- $day = intval(substr($idcode, 5, 2));
- $centuryPrefix = 0;
- switch($century) {
- case 1:
- case 2:
- $centuryPrefix = '18';
- break;
- case 3:
- case 4:
- $centuryPrefix = '19';
- break;
- default:
- $centuryPrefix = '20';
- break;
- }
- $fullYear = $centuryPrefix.$year;
- $bday = mktime(0, 0, 0, $month, $day, $fullYear);
- $age = intval(substr(date('Ymd') - date('Ymd', $bday), 0, -4));
- return array('age' => $age);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement