# Sort by date entered inside structure field

**URL:** <https://forum.getkirby.com/t/sort-by-date-entered-inside-structure-field/6609>\
**Category:** Questions\
**Tags:** v2\
**Created:** [February 13, 2017, 3:43pm UTC](https://forum.getkirby.com/t/sort-by-date-entered-inside-structure-field/6609 "2017-02-13T15:43:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![S1SYPHOS](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/s1syphos/32/3671_2.png) [@S1SYPHOS](https://forum.getkirby.com/u/S1SYPHOS)\
**Post date:** [February 13, 2017, 3:43pm UTC](https://forum.getkirby.com/t/sort-by-date-entered-inside-structure-field/6609/1 "2017-02-13T15:43:16Z")

</div>

Hey there.  
I’m looking for a way to sort entries of a structure field by one of its field values (which is a date):

```yaml
events:
  label: Calendar
  type: structure
  entry: >
    <strong>{{summary}}</strong><br>
    {{description}}<br>
  fields:
    summary:
      label: Summary
      type: text
    description:
      label: Description
      type: textarea
    begin_date:
      label: Start
      type: date
    end_date:
      label: End
      type: date

```

and my template looks like this:

```php
<?php $events = $page->events($own = true, $allies = array('children' => true, 'siblings' => true)); ?>
<?php foreach ($events as $key => $event) : ?>
  <?php snippet('event-teaser', array('event' => $event)); ?>
<?php endforeach ?>

```

Now I tried different things, like appending `->sortby(begin_date(), 'desc')` to the `$events` definition, but nothing seems to work really … I replaced begin\_date with different `toStructure()` calls and stuff like this to access the begin\_date field, but I am stuck really …

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [February 13, 2017, 3:59pm UTC](https://forum.getkirby.com/t/sort-by-date-entered-inside-structure-field/6609/2 "2017-02-13T15:59:14Z")

</div>

This should work:

```auto
$events = $events->sortBy('begin_date', 'desc');

```

---

<div class="post-metadata">

**Author:** ![S1SYPHOS](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/s1syphos/32/3671_2.png) [@S1SYPHOS](https://forum.getkirby.com/u/S1SYPHOS)\
**Post date:** [February 13, 2017, 4:01pm UTC](https://forum.getkirby.com/t/sort-by-date-entered-inside-structure-field/6609/3 "2017-02-13T16:01:52Z")

</div>

Totally, thank you (once again)!

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 4:52pm UTC](https://forum.getkirby.com/t/sort-by-date-entered-inside-structure-field/6609/4 "2025-02-06T16:52:45Z")

</div>


