I'm using a conditional statement to compare the current date with a date of a custom post type. I'm using ACF for the date field of the custom post.

The statement works fine if the date of the event is in the current year. However if I change the date to a date in 2018 the statement fails.

I only have no clue why this fails. This is my code which is fine if both dates are in the same year.

$today = new DateTime();
$date_event = DateTime::createFromFormat('j F Y', get_field('date_event'));

if($date_event > $today && is_singular('events') && get_field('aanmeldformulier_tonen')) :;?>

// do stuff

<?php else:?>

closed as off-topic by Nicolai, Jacob Peattie, cjbj, Jack Johansson, EAMann Dec 25 '17 at 4:14

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Try another format, like Y-m-d. – Nicolai Dec 7 '17 at 13:46
  • 1
    That pointed me in the right direction, I had to save it in Y-m-d format instead of j F Y. Thanks! – NielsPilon Dec 7 '17 at 13:55

You might need to convert the time to timestamps (not php time formatting) for comparison purposes. I always found that it solved a lot of my event issues.

Not the answer you're looking for? Browse other questions tagged or ask your own question.