1

Hi I'm trying to template out a simple conditional that shows content if the date set in a date field is greater or equal to today, and I can't seem to get the syntax quite right.

I have tried this:

{% if entry.promoEndDate|date ('>= ' ~ now) %}
    <p class="price--notes">Price valid until {{ entry.promoEndDate | date('d M Y') }}</p>
{% endif %}

And this:

{% if entry.promoEndDate | date >= now | date %}
    <p class="price--notes">Price valid until {{ entry.promoEndDate | date('d M Y') }}</p>
{% endif %}

Both don't yield the result I'm looking for. Probably missing something really simple here but looked at it too long now.

Thanks in advance

1

You should be able to just compare the two dates directly.

{% if entry.promoEndDate >= now %}
    <p class="price--notes">Price valid until {{ entry.promoEndDate|date('d M Y') }}</p>
{% endif %}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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