Using a matrix Date/Time field to sort entries I'm trying to use Supersort to sort entries using a date/time field within a matrix, for example 1/6/2019 12:00AM. These dates will always be in the future. I want to sort it so that the entries that are closest to happening are displayed first. 

To make it more complicated, entries with multiple dates in the matrix are split apart, so I need to sort each of these according to their date (from https://gocrowsnest.ca/events):



I can't figure out how exactly I'm supposed to do this. What I have: 

{% set pageEntries = craft.entries.section('events') | supersort('sortAs', '{dates.type("date").first.startDate.getTimestamp}') %}
{% for event in pageEntries %}
    {% for block in event.dates.all() %}
        {# Event code #}
    {% endfor %}
{% endfor %}


This is sorting each entry by the first matrix date, not by each date.

Matrix handle: dates, block: date, field (date/time): startDate.
So you're not getting your matrix field's value properly. You're going to want to access it the same way you'd output the data:

{{ event.dates.type('date').first().startDate.getTimestamp() }}


So what we're doing here is getting the dates matrix field, selecting the blocks that have a type of date, getting the first of those blocks (should be our only block but .first is still needed), then get the startDate field in that block. During my testing I found you needed something like .getTimestamp() or .atom() to turn the date into a string that SuperSort could understand (not sure why the examples in our docs don't use that, will definitely look into that though).

So something like this should achieve what you're looking for:

{% set pageEntries = craft.entries.section('events') | supersort('sortAs', '{dates.type("date").first.startDate.getTimestamp}') %}
{% for event in pageEntries %}
    {# event data #}
{% endfor %}


Hopefully that helps!


  Fwiw, I work for TopShelfCraft (who made the SuperSort plugin)