# filterBy dates with intl config

**URL:** <https://forum.getkirby.com/t/filterby-dates-with-intl-config/28294>\
**Category:** Questions\
**Created:** [April 4, 2023, 7:11am UTC](https://forum.getkirby.com/t/filterby-dates-with-intl-config/28294 "2023-04-04T07:11:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pixelliquid](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/pixelliquid/32/10293_2.png) [@pixelliquid](https://forum.getkirby.com/u/pixelliquid)\
**Post date:** [April 4, 2023, 7:11am UTC](https://forum.getkirby.com/t/filterby-dates-with-intl-config/28294/1 "2023-04-04T07:11:15Z")

</div>

I show a structure with dates involved. I like to only show future entries. After following [this thread](https://forum.getkirby.com/t/sort-filter-entries-from-a-structure-field/14942/4) I thought I could use the same, but I get the error “Object of class Kirby\Cms\Field could not be converted to int” so it has to do with the dates being international… I have a multilanguage setup and use `'date.handler' => 'intl'` in my config. I’m not fluent in php so I’m a bit lost now.

This is my code:

```auto
foreach ($productions as $production):
    $items = $production->playdates()->toStructure()->filterBy('playdate','>',strtotime('now'))->sortBy('playdate', 'desc');
    foreach ($items as $item): ?>
      <li>
        <span><?= $item->playdate()->toDate('EEEE d MMMM Y – H:mm') ?></span>
        <span><?= $production->title() ?></span>
        <span><?= $item->location() ?></span>
        <span><?= $item->city() ?></span>
        <?php if ($item->ticketlink()->isNotEmpty()): ?>
          <a href="<?= $item->ticketlink() ?>">tickets</a>
        <?php endif ?>
      </li>
    <?php endforeach ?>
  <?php endforeach ?>

```

As always the solution is just around the corner…

---

<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:** [April 4, 2023, 12:02pm UTC](https://forum.getkirby.com/t/filterby-dates-with-intl-config/28294/2 "2023-04-04T12:02:49Z")

</div>

> [@pixelliquid](#):
>
> ` $items = $production->playdates()->toStructure()->filterBy('playdate','>',strtotime('now'))->sortBy('playdate', 'desc');`

```auto
$items = $production->playdates()->toStructure()->filterBy('playdate', 'date >', time())->sortBy('playdate', 'desc');

```

---

<div class="post-metadata">

**Author:** ![pixelliquid](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/pixelliquid/32/10293_2.png) [@pixelliquid](https://forum.getkirby.com/u/pixelliquid)\
**Post date:** [April 4, 2023, 1:03pm UTC](https://forum.getkirby.com/t/filterby-dates-with-intl-config/28294/3 "2023-04-04T13:03:46Z")

</div>

Originally I had this as well, but there was nothing rendered. When I omitted the `filterBy` part all entries showed up. Then I tried both `time()` and `strtotime()` as I thought it was language related, but I’ve misread the “int” for “intl” so it’s not language related…  
this is how the blueprint and content of those playdates look like:

`blueprint`

```auto
label: Playdates
type: structure
fields:
  playdate:
    type: date
    time: true
  location:
    type: text
  city:
    type: text
  ticketlink:
    type: url

```

`content`

```auto
Playdates:

- 
  playdate: 2023-03-30 22:15:00
  location: Toneelschuur
  city: Haarlem
  ticketlink: https://schuur.nl/programma/op-datum
  link: https://www.schuur.nl/programma/op-datum
- 
  playdate: 2023-04-28 20:00:00
  location: Caprera
  city: Bloemendaal
  ticketlink: https://caprera.nu/programma/

```

---

<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:** [April 4, 2023, 1:14pm UTC](https://forum.getkirby.com/t/filterby-dates-with-intl-config/28294/4 "2023-04-04T13:14:16Z")

</div>

> [@pixelliquid](#):
>
> $items = $production-\>playdates()-\>toStructure()-\>filterBy(‘playdate’,‘\>’,strtotime(‘now’))-\>sortBy(‘playdate’, ‘desc’);

Then change to

```auto
<?php $items = $production->playdates()->toStructure()->filter(fn($item) => $item->playdate()->toDate() > time())->sortBy('playdate', 'desc');

```

---

<div class="post-metadata">

**Author:** ![pixelliquid](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/pixelliquid/32/10293_2.png) [@pixelliquid](https://forum.getkirby.com/u/pixelliquid)\
**Post date:** [April 4, 2023, 2:31pm UTC](https://forum.getkirby.com/t/filterby-dates-with-intl-config/28294/5 "2023-04-04T14:31:04Z")

</div>

You rock! 🤘 Seriously, the Kirby support is so helpful in contrast to others!  
As always your solution works. I didn’t know about the `filter(fn($item))` method. Still scratching the surface 🙂
