Support

Account

Home Forums General Issues Date picker as expiry for custom field

Unread

Date picker as expiry for custom field

  • Hi,

    I’m hoping someone can help me out with the issue that I have encountered with the ACF date-picker field.

    I have created an announcement banner for a website through ACF. The announcement banner consists of 2 fields. One field with the banner message (textarea field) and another field as an expiry date (datepicker field) for the banner.

    Snippet of the code I am using is below.

    <?php
    $current_date_time = current_datetime()->format(‘d/m/Y’);
    $noticeExpiry = get_field(‘notice_expiry’, ‘options’)
    ?>

    <?php if ($noticeExpiry > $current_date_time ) {?>
    <div class=”notice-banner”>
    <div class=”wrap”>
    <?php the_field(‘website_notice’,’options’) ?>
    </div>
    </div>
    <?php } ?>

    As you can see I have a conditional statement that checks todays date against the notice expiry and if the $noticeExpiry is a future date compared to the current date the notice banner will display.

    The problem that I am having is that the condition only appears to with working with the numeric value of the days.

    If I set the expiry as yesterday (11/2/24) then all is working as expected. The banner will not appear. However if I change the date to a date that exceeds the 11th date of a previous month the banner appears. Something I spotted when I was testing. I changed the expiry date to 29/1/24 and when I published the change the banner started to appear again. If I change the date to 10/1/24 the banner does not appear.

    Appreciate any help on this and apologies if I am missing something super basic.

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.