<p>I hope I am not completely missing the point, but I guess like that:</p>

<p>Initial 5:</p>

<pre><code>{% for block in block.eventList.eventDate('&gt;=' ~ (now|atom)).orderBy('eventDate asc').limit(5).all() %}
     {{ block.eventTitle }}
{% endfor %}
</code></pre>

<p>rest:</p>

<pre><code>{% for block in block.eventList.eventDate('&gt;=' ~ (now|atom)).orderBy('eventDate asc').offset(5).all() %}
          {{ block.eventTitle }}
{% endfor %}
</code></pre>

<p>past events:</p>

<pre><code>{% for block in block.eventList.eventDate('&lt;' ~ (now|atom)).orderBy('eventDate desc').all() %}
     {{ block.eventTitle }}
{% endfor %}
</code></pre>

<p>you will probably need to change the <code>date('Y-m-d')</code> format</p>

CC BY-SA 4.0
2020-05-16T22:03:15.120Z
Thanks so much! This works, except it doesn't output anything for past events (even though there are events with dates prior to today). Any reason that could be? Thanks again
univers_
CC BY-SA 4.0
2020-05-17T20:07:50.063Z
ok, I just learned something here: the filter to use is not date(...) but |atom instead. With this it works. I also player around a little bit with the date filter to check that and never got it to work. don't know why... anyway, use |atom. And parenthesis. I changed the answer above.
Matthias Redl-Mann
CC BY-SA 4.0
2020-05-17T20:13:41.710Z
ok, the real solution: I was missing the parenthesis with (now|atom). You could also go (now|date('Y-m-d')) if you e.g. just wanted to consider the day but not the time of now, which |atom does.
Matthias Redl-Mann
CC BY-SA 4.0
2020-05-16T20:06:13.133Z
2020-05-17T20:09:36.273Z
2020-05-17T20:09:36.273Z
Matthias Redl-Mann
<p>I'm using a matrix inside a Super Table to organize events, and I'd like to order the events using the date field for each event.</p>

<p>I'm currently showing the first five events using <code>limit</code> then using <code>offset</code> to show the rest of the blocks after the first five. Then I'm separating future and past events using the date field. Like this:</p>

<p>First five upcoming events:</p>

<pre><code>{% for block in block.eventList.limit(5) %}
     {% if block.eventDate &gt;= now %}
          {{ block.eventTitle }}
     {% endif %}
{% endfor %}
</code></pre>

<p>The rest of the upcoming events:</p>

<pre><code>{% for block in block.eventList.offset(5) %}
     {% if block.eventDate &gt;= now %}
          {{ block.eventTitle }}
     {% endif %}
{% endfor %}
</code></pre>

<p>All past events:</p>

<pre><code>{% for block in block.eventList %}
     {% if block.eventDate &lt;= now %}
          {{ block.eventTitle }}
     {% endif %}
{% endfor %}
</code></pre>

<p>This works fine as is, but it doesn't sort the events within the sections by the date field. How can I add that?</p>

<matrix><datetime><blocks><sort>
Order matrix blocks by date field
# Order matrix blocks by date field

(Asked by: username_0 on 2020-05-15)

I'm using a matrix inside a Super Table to organize events, and I'd like to order the events using the date field for each event.
I'm currently showing the first five events using limit then using offset to show the rest of the blocks after the first five. Then I'm separating future and past events using the date field. Like this:
First five upcoming events:
{% for block in block.eventList.limit(5) %}
     {% if block.eventDate >= now %}
          {{ block.eventTitle }}
     {% endif %}
{% endfor %}

The rest of the upcoming events:
{% for block in block.eventList.offset(5) %}
     {% if block.eventDate >= now %}
          {{ block.eventTitle }}
     {% endif %}
{% endfor %}

All past events:
{% for block in block.eventList %}
     {% if block.eventDate <= now %}
          {{ block.eventTitle }}
     {% endif %}
{% endfor %}

This works fine as is, but it doesn't sort the events within the sections by the date field. How can I add that?

**Tags:** matrix, datetime, blocks, sort

---

## 1 answers

### Answer by username_1 on 2020-05-16. Score: 1 | Accepted answer

I hope I am not completely missing the point, but I guess like that:
Initial 5:
{% for block in block.eventList.eventDate('>=' ~ (now|atom)).orderBy('eventDate asc').limit(5).all() %}
     {{ block.eventTitle }}
{% endfor %}

rest:
{% for block in block.eventList.eventDate('>=' ~ (now|atom)).orderBy('eventDate asc').offset(5).all() %}
          {{ block.eventTitle }}
{% endfor %}

past events:
{% for block in block.eventList.eventDate('<' ~ (now|atom)).orderBy('eventDate desc').all() %}
     {{ block.eventTitle }}
{% endfor %}

you will probably need to change the date('Y-m-d') format

> **Comments:**
> **username_0**: Thanks so much! This works, except it doesn't output anything for past events (even though there are events with dates prior to today). Any reason that could be? Thanks again  
> **username_1**: ok, I just learned something here: the filter to use is not date(...) but |atom instead. With this it works. I also player around a little bit with the date filter to check that and never got it to work. don't know why... anyway, use |atom. And parenthesis. I changed the answer above.  
> **username_1**: ok, the real solution: I was missing the parenthesis with (now|atom). You could also go (now|date('Y-m-d')) if you e.g. just wanted to consider the day but not the time of now, which |atom does.  

---

