filterBy dates with intl config

I show a structure with dates involved. I like to only show future entries. After following this thread 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:

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…

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

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

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

content

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/

Then change to

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

You rock! :metal: 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 :slight_smile: