주민번호로 나이 구하기 (소수점까지)
페이지 정보
조회
19,734
본문
특이한점은 달에 따라서 나이를 소수점으로 구해줍니다(예: 1982년04년27월생->22.4세)
단 예외는 19xx 년생의 경우만 처리 가능합니다.
function getage($jumin) {
$res='';
if(strlen($jumin)>=6){
$t_year=intval('19'.substr($jumin,0,2));
$t_mon=intval(substr($jumin,2,2));
$t_day=intval(substr($jumin,4,2));
if(checkdate($t_mon,$t_day,$t_year)){
$t = mktime(0,0,0,$t_mon,$t_day,$t_year);
$nt = time();
$t2 = $nt-$t;
if($t2>0)
$res = round($t2 / 86400 / 365 + 1, 1);
}
}
return $res;
}
관련자료
등록된 댓글이 없습니다.