채택완료

시간 차이 질문 입니다.

2021-06-23 (수) 14:10:13 2,169

몇시간 몇분 남았습니다. 라고 나오게 하고 싶습니다.

시간, 분 차이를 어떻게 수정해줘야 할까요?

Copy
$sql = " select * from g5_write_request order by wr_id desc limit 1 ";
$result = sql_fetch($sql);

 

$now = date("Y-m-d H:i:s");
$totime = date("Y-m-d H:i:s", strtotime($result['wr_datetime']."+3 hours"));

$hour = '';
$minutes = '';

 

if($now < $totime) {
    alert('예약 가능 시간까지 '.$hour.'시간 '.$minutes.'분 남았습니다.');
}
|

답변 2개

채택된 답변
+20 포인트
Copy
<?php
$result['wr_datetime'] = '2021-06-23 14:00:00';
$time = strtotime($result['wr_datetime']."+3 hours") - time();
$hour = floor($time / (60*60));
$minutes = floor(($time % (60*60)) / 60);
echo $hour.' 시간 '.$minutes.' 분 남았습니다.';
Copy
date_default_timezone_set('Asia/Seoul');


$sql = " select * from g5_write_request order by wr_id desc ";
$result = sql_fetch($sql);

$now = strtotime(date('Y-m-d H:i:s'));

$totime = strtotime(date("Y-m-d H:i:s", strtotime($result['wr_datetime']."+3 hours")));

$results = $totime-$now;

$hour = floor($results/3600);

$results = $results - ($hour * 3600);

$minutes = floor($results / 60);


if($now < $totime) {
    alert('예약 가능 시간까지 '.$hour.'시간 '.$minutes.'분 남았습니다.');
}

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