주민번호로 나이 구하기 (소수점까지)
컨텐츠 정보
- 23,381 조회
 - 11 추천
 - 목록
 
본문
				주민 번호를 이용해서 나이를 구하는 함수입니다.
특이한점은 달에 따라서 나이를 소수점으로 구해줍니다(예: 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;
}
			
					특이한점은 달에 따라서 나이를 소수점으로 구해줍니다(예: 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;
}
관련자료
			댓글 0
					
			
				등록된 댓글이 없습니다.