Condition for current date comparison with ACF field date

Hi,

I have a date field in ACF which has the following output format j M Y and I need to compare it with the current date to show or hide an element. How should I do this properly?

If I choose Today before / after and {{ dc:acf:post_field field="event-start-date" }} it doesn’t work the way it should. Should I use a Datetime expression and specify its format to match the earlier mentioned ACF field date output?

What should it be so I could compare them properly? {{ global.date({"format":"j M Y"}) }} Please advice.

Hey John,

Try adding type=date to your ACF DC like {{dc:acf:post_field field="event-start-date" type="date"}}

Hi @christian,

It didn’t help, unfortunately. Even more than that, if I use it I get the following error on Cornrestone page reload. If I delete it, the issue disappears.

Hey @referee,

I’d recommend you don’t use the format for comparing as that just create complexity and the issue. Please use the default d/m/Y instead.

image

Okay, thanks @christian .

The problem I still had after this comment was that the {{ global.date }} still returned a different format. It wasn’t d/m/Y. It was m/d/Y so the conditions didn’t work the way they should.

After changing the default date format in WordPress Settings to match the ACF date field format, it began to be interpreted correctly.

It works with custom date formats as well, except for “j M Y.” I suppose we can use various date format combinations as long as they are recognized by WordPress (d, m, Y). Not other PHP date formats will work, I suppose, but I will experiment with that later.

Hello John,

Good to know that changing the default date format resolves the issue.

Cheers.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.