Lawyer
Lawyer

Reputation: 3

Advanced Custom Fields - Compare Datepicker Date with current date

I need help to display a simple message when one of my seminars ends. I have something like "This seminar has ended" in mind, but can't figure out the right formats. I'm using wordpress and the Advanced Custom Fields (ACF) plugin for custom fields:

Code:

    <?php 

        $today = date('Ymd');
        $sem_date = get_field('sem_date'); // Output format d / m / y  (has to be this format on the site)

        if($today > $sem_date){ ?>

        <div class="oops">
            This seminar has ended!
        </div>  

    <?php } ?>

Upvotes: 0

Views: 1552

Answers (1)

Scriptonomy
Scriptonomy

Reputation: 4055

Get today's date as a Date Object:

$today = new DateTime( 'today', new DateTimeZone('America/Chicago') );

Get seminar's date as a Date Object:

$sem_date = new DateTime( get_field('sem_date') );

Now you can compare the two Date objects:

$today > $sem_date

Upvotes: 1

Related Questions