Answers.Body: <p>Thanks Marten, yes, that's correct.</p>
  
  <p>After plugging away I have gotten it to work, but it's likely not as efficient as it could be...</p>
  
  <pre><code>{% set today = now|date('Y-m-d') %}
  {% set todayday = now|date('l') %}
  {% for block in entry.closedDates.date('&gt;=' ~ today).limit(1) %}
      {% set closedDate = block.date.format('Y-m-d') %}
      {% if closedDate == today %}
          &lt;p&gt;&lt;strong&gt;It's a holiday, sorry, we're closed&lt;/strong&gt;&lt;/p&gt;
      {% elseif todayday == 'Sunday' %}
          &lt;p&gt;&lt;strong&gt;It's {{ todayday }}, sorry, we're closed&lt;/strong&gt;&lt;/p&gt;
      {% else %}
          &lt;p&gt;We're Open!&lt;/p&gt;
      {% endif %}
  {% endfor %}
  </code></pre>
  
  <p>I added a check for whether today is Sunday, which is a normally closed day that would not be in the entry.</p>
  
  <p>Doug</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-05-29T11:50:24.747Z
Answers.LastActivityDate: 2020-05-29T11:50:24.747Z
Answers.UserDisplayName: dbigca
Body: <p>I'm struggling with filtering future dates in a Matrix block that contains a date field.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>My code...</p>
  
  <pre><code>{% set closed = craft.block('closedDates')
      .type('closedDate')
      .date('&gt;=' ~ today)
      .all() %}
  {% for block in entry.closedDates.all() %}
      {% if today == closed %}
          &lt;p&gt;&lt;strong&gt;Closed&lt;/strong&gt;&lt;/p&gt;
      {% else %}
          &lt;p&gt;Open&lt;/p&gt;
      {% 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.
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-05-28T07:21:30.130Z
Comments.Text: 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?
Comments.UserDisplayName: Marten Brosch
Tags: <matrix><search>
Title: Filtering a Matrix block for future dates
ThreadText: # Filtering a Matrix block for future dates
  
  (Asked by: username_0 on 2020-05-27)
  
  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')
      .type('closedDate')
      .date('>=' ~ today)
      .all() %}
  {% for block in entry.closedDates.all() %}
      {% if today == closed %}
          <p><strong>Closed</strong></p>
      {% else %}
          <p>Open</p>
      {% 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.
  
  ```
  
  **Tags:** matrix, search
  
  > **Comments:**
  > **username_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?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2020-05-29. Score: 2 | Accepted answer
  
  Thanks username_1, 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.
  
  Doug
  
  
  ---
  
  