Support

Account

Home Forums ACF PRO Date Field – change div class based by date Reply To: Date Field – change div class based by date

  • What is the date format of the date field?

    In order to compare 2 dates the dates must be in the same format and that format must have the year first, month second and day last (“Ymd” or “Y-m-d” or “Y/m/d”). in the format you are using dmY 12-30-1900 (Dec 30, 1900) will always be greater than any other date combination for example 01-01-2021 (Jan 1, 2021), “01” is less than “12”

    
    // unformatted date
    $webinarDateUnformatted = get_sub_field('webinar-date', false, false);
    $now = date('Ymd');
    if ($webinarDateUnformatted < $now) {
      // date is less than now
    }