I'm trying to change $showThis
based on whichever date is closest to now. How can I compare the time differences? Currently $interval1 > $interval2
does not work. I know the difference is being calculated, but I'm not sure how to compare the two.
$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');
}
Use
getTimestamp
method.