0
현재 가장 가까운 날짜를 기준으로 $showThis
을 변경하려고합니다. 시차를 어떻게 비교할 수 있습니까? 현재 $interval1 > $interval2
이 작동하지 않습니다. 나는 차이가 계산되고 있음을 알고 있지만 두 가지를 비교하는 방법을 모르겠습니다.PHP - 현재 날짜로부터 두 미래 날짜를 비교하십시오.
$currentTime = new DateTime("now");
$wednesday = new DateTime('wednesday 10:59pm');
$saturday = new DateTime('saturday 10:59pm');
$interval1 = $currentTime->diff($wednesday);
$interval2 = $currentTime->diff($saturday);
if($interval1 > $interval2){
$showThis = $saturday->format('D m/d/Y h:i A');
}
if($interval1 < $interval2){
$showThis = $wednesday->format('D m/d/Y h:i A');
}
날짜 시간의 사랑하는 방법은 DateInterval http://php.net/manual/en/class 반환합니다. dateinterval.php – kyle