I have an Event lister loop, where I made variables from the Event’s dates and today date. There is a Required $maindate, but there are also other dates of the same event $otherdates, which are later than the main.
I want to set-up the latest date that is set in a separate variable, and compare it to the today’s date to have the if ( $comparedate >= $today ) controlling the listing only the future events.
Here are my variables:
$maindate = DateTime::createFromFormat('Ymd', get_field('date'));
$otherdates1 = DateTime::createFromFormat('Ymd', get_field('other_dates'));
$otherdates2 = DateTime::createFromFormat('Ymd', get_field('other_dates_2'));
$otherdates3 = DateTime::createFromFormat('Ymd', get_field('other_dates_3'));
$today = DateTime::createFromFormat('Ymd', date('Ymd'));
/* I need to set up the first available variable here */
$comparedate = $otherdates3 || $otherdates2 || $otherdates1 || $maindate;
if ( $comparedate >= $today ) :
/* list the future events */
How can I make this comparison?
As pointed by Ianis, I had to compare the variables by php max operator, and the if statement gets the latest date like that.
The variable is: