날짜계산 문의드립니다.
본문
나이 구하는 구문을 찾아 넣으려고 하는데요 아래 코드는 정상적으로 나이가 출력되는데,
1980-1-2 가 들어있는 필드 birth를 넣으면 출력이 되지 않습니다.
$birth_time = strtotime($birth);
$birth_time = $list[$i]['birth']; 등으로 넣어봐도 되지않아 문의드립니다 ㅠㅠ
<?php
$birth_time = strtotime('1980-1-2');
$now = date('Y');
$birthday = date('Y' , $birth_time);
$age = $now - $birthday + 1 ;
?>
답변 2
예제코드는 strtotime으로 변형하면서 필드값은 그대로 사용하면 되겟습니까?
birth필드가 날짜라면 아래처럼 해야겠죠
$birth_time = strtotime($list[$i]['birth']);
list.skin.php 의 $list 루프문 안에서, 하나씩 확인하면서 살펴보는 것이 어떨까 합니다.
(birth 필드가 varchar 타입으로 되어있는지, date 타입으로 되어있느지, datetime 타입으로 되어있는지도 확인해보는 것이 좋을 듯 합니다.)
참고 예저입니다.
<?php
for ($i=0; $i<count($list); $i++) {
//$list[$i]['birth'] = '1980-1-2';
$birth_time = strtotime($list[$i]['birth']);
// echo $list[$i]['birth'];
$now = date('Y');
$birthday = date('Y' , $birth_time);
// echo $birthday;
$age = $now - $birthday + 1 ;
echo $age;
?>
!-->
답변을 작성하시기 전에 로그인 해주세요.