Sort page collection by date and time

The situation

I have a page collection with children of a lot of different (!) pages and they are sorted ascending by date:

My code looks like this:

<?php $matches = $site->index()->filterBy('template', 'match')->filterBy('date', '>=',time()-24*60*60)->sortBy('date','asc'); ?>

My blueprint contains a date field and a time field:

    label: Datum
    type: date
    format: DD.MM.YYYY
    width: 1/2
    label: Uhrzeit
    type: time
    interval: 5
    width: 1/2

The problem

I would like to sort the matches by date and time!

##The workaround

If there’s no better solution I will add a readonly timestamp field to the blueprint, use panel hooks to save the calculated value and sort by this field … but there must be an easier solution!?

Any ideas?

By the way, I found Sorting of the subpages by date **AND** time but unfortunately that doesn’t help me :confused:

The following code should work:

$matches = $site->index()->filterBy('template', 'match')->filterBy('date', '>=', time()-24*60*60)->sortBy('date', 'asc', 'time', 'asc');

It sorts the items by date and then (inside the same day) by time.

1 Like

Works. Awesome. Thanks a lot!