PHP with GNU date() - 날짜 비교, 계산 with GNU
페이지 정보
작성자 디자인천일
작성일Date: 2025-03-27 21:02
조회view: 5
본문
date() - 날짜를 비교하여 이벤트 시작, 진행, 종료 표시
php
$current_date = strtotime(date('Y-m-d H:i:s')); //현재날짜
$sdate = $list[$i]['wr_5'].' 00:00:00'; //이벤트 시작일
$edate = $list[$i]['wr_6'].' 00:00:00'; //이벤트 종료일
$sdate = strtotime($sdate);
$edate = strtotime($edate);
$start_diff = ($current_date - $sdate)/3600;
$end_diff = ($current_date - $edate)/3600;
if($start_diff >= 0 && $end_diff < 0) {
$stat = '<span class="event_ing"><i class="xi-alarm xi-x"></i>진행중</span>';
} else if($start_diff < 0 && $end_diff < 0) {
$stat = '<span class="event_ready"><i class="xi-alarm-o xi-x"></i>예정</span>';
} else {
$stat = '<span class="event_end"><i class="xi-alarm-off xi-x"></i>종료</span>';
}
echo '<div class="period">';
echo $stat.' ';
echo date("Y년 m월 d일", strtotime($list[$i]['wr_5'])).' ~ ';
echo date("Y년 m월 d일", strtotime($list[$i]['wr_6']));
echo '</div>';