1

I need to display an entry only if the date fields within its Matrix are current. So, only display if the startDate is greater than or equal to today and the endDate is less than or equal to today.

Currently I have this code and am having trouble finding how to compare multiple dates.

{% for entry in craft.entries.section('sectionHandle') %}
    {% set present = now|date %}
    {% set entryStart = entry.matrixHandle.startDate %}
    {% set entryEnd = entry.matrixHandle.endDate %}

    {% if entryStart >= present and entryEnd <= present %}
        display entry information
    {% endif %}
{% endif %}

I'm guessing that I'm using the operators incorrectly or that "and" isn't allowed. Either way, it's not displaying anything and yes, I have a made sure that I have an entry with dates that would activate this if statement.

2

I think you've just got a logic problem.

{% if entryStart >= present and entryEnd <= present %}

The only way this will ever evaluate to true is if the entryStart and entryEnd DateTime fields have the exact same date and time (down to the second) that the present time is, which seems like a very small window.

You're essentially looking for an entry that lives in the future and in the past.

  • would changing it to {% if entryStart <= present and entryEnd >= present %} fix what I'm trying to do? Been working on these things for a while and just need another set of eyes to make sense of it. – Indigo Viking Sep 23 '16 at 11:03
  • Can you explain in words when you'd want the entry information to be shown. – Brad Bell Sep 23 '16 at 23:56
  • your solution fixed this problem. my logic was just incorrect. – Indigo Viking Apr 19 '18 at 14:39

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.