테스트 사이트 - 개발 중인 베타 버전입니다

생일 년도 표시 방법 채택완료

수아주환 11년 전 조회 9,044

생년월일을 입력 받았습니다..

 

예) 1980-11-14

 

이렇게 [mb_4]에  값이 입력되어 있습니다..

 

 

이 값을 이용하여 나이를 구하고 싶습니다.( 만나이 말고 그냥 나이)

 

즉 현재 년도에서 생년월일 년도를 빼고 +1 을 해서 나이 표시를 하고 싶은데...

 

소스를 어떻게 해야 하나요...

 

 

표시 예) 현재 나이 -> 35세

댓글을 작성하려면 로그인이 필요합니다.

답변 2개

채택된 답변
+20 포인트
T
11년 전

</p><p><?php</p><p># 특정 회원의 특정 정보(<span style="font-size: 10pt; line-height: 1.5;">mb_id, mb_name, mb_4</span><span style="font-size: 10pt; line-height: 1.5;">​</span><span style="font-size: 10pt; line-height: 1.5;">)를 호출</span></p><p>$mb = get_member('아이디', 'mb_id, mb_name, mb_4');</p><p>/*</p><p><span style="font-size: 10pt; line-height: 1.5;">$mb의 내용</span><span style="font-size: 10pt; line-height: 1.5;">​</span></p><p>array(</p><p>    'mb_id' => '아이디',</p><p>    'mb_name' => '아무개',</p><p>    'mb_4' => '<span style="font-family: gulim, helvetica; line-height: 23.5440006256104px; font-size: 10pt; background-color: rgb(255, 255, 255);">1980-11-14</span><span style="font-size: 10pt; line-height: 1.5;">​</span><span style="font-size: 10pt; line-height: 1.5;">'</span></p><p><span style="font-size: 10pt; line-height: 1.5;">);</span></p><p>*/</p><p># 만 나이</p><div>$age_ = ( date('Y') - date('Y', strtotime($mb['mb_4'])) );​</div><div>
</div><div># 만 나이 +1</div><div><span style="font-size: 10pt; line-height: 1.5;">$age = </span><span style="font-size: 10pt; line-height: 1.5;">$age_</span><span style="font-size: 10pt; line-height: 1.5;">​</span><span style="font-size: 10pt; line-height: 1.5;"> +1;</span></div><div><span style="font-size: 10pt; line-height: 1.5;">
</span></div><div><span style="font-size: 10pt; line-height: 1.5;"># 출력</span></div><div><p>echo <span style="font-size: 10pt; line-height: 1.5;">$mb['mb_name'] .'(' .</span><span style="font-size: 10pt; line-height: 1.5;">​</span><span style="font-size: 10pt; line-height: 1.5;">$mb['mb_id'] </span><span style="font-size: 10pt; line-height: 1.5;">​.') 님의 나이는 '. $age .'(만'. </span><span style="font-size: 10pt; line-height: 1.5;">$age_ </span><span style="font-size: 10pt; line-height: 1.5;">​</span><span style="font-size: 10pt; line-height: 1.5;">.')세 입니다.';</span></p><p>

 

 

 

 

간단하게 하면

</p><p><?php</p><p>echo <span style="font-size: 10pt; line-height: 1.5;"> </span><span style="font-size: 10pt; line-height: 1.5;">( date('Y') - date('Y', strtotime('</span><span style="font-size: 10pt; font-family: gulim, helvetica; line-height: 23.5440006256104px; background-color: rgb(255, 255, 255);">1980-11-14</span><span style="font-size: 10pt; line-height: 1.5;">​</span><span style="font-size: 10pt; line-height: 1.5;">​')) ) +1;</span></p><p><span style="font-size: 10pt; line-height: 1.5;">

입니다.​

 

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

수아주환
11년 전
감사합니다..^^

댓글을 작성하려면 로그인이 필요합니다.

11년 전

</p><p><?php
$born = "1980-11-14";
$now = date("Y-m-d");

$age = $now - $born + 1;

echo $age;
?> </p><p>
 

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인