SortBy function only sorting by year not full date

Hi there,

I’m trying to sort some pages by a date field. At the moment it works but not how I would expect.

$projects = $page->children()->listed()->sortBy(function ($project) {return $project- 
>projectStartDate()->toDate(); })->flip();

Have also tried:

$projects = $page->children()->listed()->sortBy('projectStartDate',  'desc')->flip();

is the code i’m using - with just a for each on the template. For some reason it is displaying the pages sorted by year but completely ignoring the month. Any suggestions?


Hm, I tested this in a Starterkit, even renamed the date field in the notes to projectStartDateand can’t reproduce your issue. Also tried with setting strftime as date handler.

Are you using the Panel to enter your dates or manually with a special date format?

Hey @texnixe, I’ve just used the below in the panel

        label: Project Start Date
        type: date
        time: false
        required: true
        default: now

But this is the order displayed:

April 2019

May 2018

September 2018

April 2018

Hm, weird. Are you using any plugins? Which Kirby version?

hey @texnixe I got it - I had it displaying as a mosaic and althought the Li’s were showing up on the right order, the mosaic was displaying them in a way which didnt make sense chronologically, just me being a muppet! Apologies!

No problem. Glad you sorted it out.