남은날짜 구하기

남은날짜 구하기

QA

남은날짜 구하기

답변 2

본문

$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  ?>">
답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
전체 129,105
© SIRSOFT
현재 페이지 제일 처음으로