date() - 날짜를 비교하여 이벤트 시작, 진행,종료 표시 > 공책

본문 바로가기
010.6356.7610
  • design1001@naver.com
  • @design1001
작업물 전체보기

PHP with GNU

PHP with GNU date() - 날짜를 비교하여 이벤트 시작, 진행,종료 표시

페이지 정보

  • 작성자후야
  • 조회 : 203
  • 작성일 : 2021-01-31 00:00

본문

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>';
}
?>

<div class="period">
	<?php echo $stat; ?>
	<?php echo date("Y년 m월 d일", strtotime($list[$i]['wr_5'])); ?> ~
	<?php echo date("Y년 m월 d일", strtotime($list[$i]['wr_6'])); ?>
</div>