I'm struggling with filtering future dates in a Matrix block that contains a date field.

I would like to display 'Open' or 'Closed' as the result of a condition checking if the value of matrix rows is today, but I only want to run the condition against future dates in the matrix block. Past dates should be ignored.

In all examples I have seen, the search logic is at declared at the entries-level, but this is a matrix block and I can't get the two to connect.

My code...

{% set closed = craft.block('closedDates')
    .date('>=' ~ today)
    .all() %}
{% for block in entry.closedDates.all() %}
    {% if today == closed %}
    {% else %}
    {% endif %}
{% endfor %}```

The (matrix) field = closedDates, the block type = closedDate, the field = date.

I prefer a matrix field so I have only 1 entry.

Would appreciate any suggestions.
  • 1
    Your matrix field consists of a date and you set the date as a "closed date" right? So block.date is the date where it is closed? May 28, 2020 at 7:21

1 Answer 1


Thanks Marten, yes, that's correct.

After plugging away I have gotten it to work, but it's likely not as efficient as it could be...

{% set today = now|date('Y-m-d') %}
{% set todayday = now|date('l') %}
{% for block in entry.closedDates.date('>=' ~ today).limit(1) %}
    {% set closedDate = block.date.format('Y-m-d') %}
    {% if closedDate == today %}
        <p><strong>It's a holiday, sorry, we're closed</strong></p>
    {% elseif todayday == 'Sunday' %}
        <p><strong>It's {{ todayday }}, sorry, we're closed</strong></p>
    {% else %}
        <p>We're Open!</p>
    {% endif %}
{% endfor %}

I added a check for whether today is Sunday, which is a normally closed day that would not be in the entry.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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