남은날짜 구하기
본문
$time = time();
$today = date("Y-m-d",strtotime("now", $time));
$month = date("Y-m-d",strtotime("+1 month", $time);
$max = $today - $month;
?>
<input type="text" name="today" id="today" value="<?php echo $today ?>">
<input type="text" name="month" id="month" value="<?php echo $month ?>">
<input type="text" name="max" id="max" value="<?php echo $max ?>">
코드는 위와 같으며
오늘날짜와 한달뒤 날짜를 구해서 뺀값을 구하고 싶습니다
오늘날짜와 한달뒤 날짜는 정상적으로 구해지는데
$max = $today - $month;
이부분에서 어떻게 뺀값을 구해야할지 감이 안잡히네요 도움좀 부탁드립니다
답변 2
<?php
$time = time();
$today = date("Y-m-d",strtotime("now", $time));
$month = date("Y-m-d",strtotime("+1 month", $time));
//$max = $today - $month;
$max_obj = date_diff(date_create($today), date_create($month));
$max = $max_obj->days;
?>
<input type="text" name="today" id="today" value="<?php echo $today ?>">
<input type="text" name="month" id="month" value="<?php echo $month ?>">
<input type="text" name="max" id="max" value="<?php echo $max ?>">
strtotime의 결과값이 타임스탬프 값이니 date함수를 사용하시기 전에 차를 먼저 구하시면 됩니다.
strtotime("+1 month") - time();
답변을 작성하시기 전에 로그인 해주세요.