<p>Would this do it?</p>

<pre><code>{% set blocks = entry.matrixFieldHandle %}
{% for block in blocks if block.yourDateField|date &gt;= now|date %}

{% endfor %}
</code></pre>

CC BY-SA 3.0
2014-06-12T09:51:43.143Z
2014-06-12T09:51:43.143Z
Espen Sandberg
<p>Here’s how you would do that:</p>

<pre><code>{% set futureEvents = entry.myMatrixField.myDateField('&gt;= '~now) %}

{% for event in futureEvents %}
    {{ event.description }}
{% endfor %}
</code></pre>

<p><strong>Update:</strong></p>

<p>This actually hadn’t worked as I expected to, but it does as of Craft 2.3.</p>

CC BY-SA 3.0
2014-08-21T15:44:20.643Z
Should this technique work with any matrix field, I have a matrix block which has a field which holds a section ID but `{% set pub = globalPubSettings.pubSettings.pubId(entry.section.id) %}` is throwing a method not found for pubId?
Sam Hibberd
CC BY-SA 3.0
2014-09-05T08:44:42.023Z
I have the same problem as Sam Hibberd, this method throws a CException "no method or closure with the name 'myDateField'".
Florian
CC BY-SA 3.0
2014-11-05T14:42:33.967Z
@BrandonKelly Is there a solution for this, just revisting and hoping I can get `{% set var = page.matrixField.showOnHome('1') %}` to work. Still throwing the same exception.
Sam Hibberd
CC BY-SA 3.0
2014-11-05T23:34:17.667Z
@SamHibberd Turns out I lied - we never got custom field-based parameters working for Matrix fields. I’ve spent the better part of the day trying to refactor some code to get it working, but unfortunately it’s looking like it won’t be possible without a breaking change to element types :-/  Stashed my work for now, and we’ll just have to revisit this for Craft 3.0.
Brandon Kelly
CC BY-SA 3.0
2014-11-06T10:58:39.497Z
@BrandonKelly :) Is there a snappy way to determine if a field is set, would search work?
Sam Hibberd
CC BY-SA 3.0
2014-11-07T00:54:22.280Z
@SamHibberd Search wouldn’t work here, no. After talking the problem over with Brad at the end of the day yesterday, I realized there was a way we could get it working before 3.0 without breaking existing element types (or at least making them any more broken then they already are in this case). Spent the day working on this, and am happy to report I’ve just gotten it all working for 2.3.
Brandon Kelly
CC BY-SA 3.0
2014-11-15T14:51:51.140Z
Does this work for you now or does it not, @Clive? Or are you already on 2.3?
carlcs
CC BY-SA 3.0
2014-06-12T10:33:37.997Z
This method is would less of an performance impact than using a conditional to determine whether or not to display the entry in a for loop.
Steve Adams
CC BY-SA 3.0
2014-06-12T09:40:25.573Z
2014-12-18T03:14:35.107Z
2014-12-18T03:14:35.107Z
Clive Portman
<p>I have a matrix field with one "event" block type that contains several fields. One of those fields is a date field. Is there a way to get just blocks with upcoming dates?</p>

<matrix><date><search>
Search matrix for blocks with upcoming dates
# Search matrix for blocks with upcoming dates

(Asked by: username_0 on 2014-06-12)

I have a matrix field with one "event" block type that contains several fields. One of those fields is a date field. Is there a way to get just blocks with upcoming dates?

**Tags:** matrix, date, search

---

## 2 answers

### Answer by username_2 on 2014-06-12. Score: 13 | Accepted answer

Here’s how you would do that:
{% set futureEvents = entry.myMatrixField.myDateField('>= '~now) %}

{% for event in futureEvents %}
    {{ event.description }}
{% endfor %}

Update:
This actually hadn’t worked as I expected to, but it does as of Craft 2.3.

> **Comments:**
> **username_7**: This method is would less of an performance impact than using a conditional to determine whether or not to display the entry in a for loop.  
> **username_3**: Should this technique work with any matrix field, I have a matrix block which has a field which holds a section ID but `{% set pub = globalPubSettings.pubSettings.pubId(entry.section.id) %}` is throwing a method not found for pubId?  
> **username_4**: I have the same problem as Sam Hibberd, this method throws a CException "no method or closure with the name 'myDateField'".  
> **username_3**: @BrandonKelly Is there a solution for this, just revisting and hoping I can get `{% set var = page.matrixField.showOnHome('1') %}` to work. Still throwing the same exception.  
> **username_5**: @SamHibberd Turns out I lied - we never got custom field-based parameters working for Matrix fields. I’ve spent the better part of the day trying to refactor some code to get it working, but unfortunately it’s looking like it won’t be possible without a breaking change to element types :-/  Stashed my work for now, and we’ll just have to revisit this for Craft 3.0.  
> **username_3**: @BrandonKelly :) Is there a snappy way to determine if a field is set, would search work?  
> **username_5**: @SamHibberd Search wouldn’t work here, no. After talking the problem over with Brad at the end of the day yesterday, I realized there was a way we could get it working before 3.0 without breaking existing element types (or at least making them any more broken then they already are in this case). Spent the day working on this, and am happy to report I’ve just gotten it all working for 2.3.  
> **username_6**: Does this work for you now or does it not, @Clive? Or are you already on 2.3?  

---

### Answer by username_1 on 2014-06-12. Score: 2

Would this do it?
{% set blocks = entry.matrixFieldHandle %}
{% for block in blocks if block.yourDateField|date >= now|date %}

{% endfor %}


---

