Filtering function with date field

hi all, i am trying to filter my collection in this way but the filter really doesn’t work [it shows me always the content]:

    $filter_date = date(param('filter_date'));
    $collection = $collection->filter(function ($page) use ($filter_date) {
        return $page->my_date_field()->toDate('d-m-Y') === $filter_date;

The format i am using to expose the param() is the same ‘d-m-Y’ i am using to filter.

I watched this page [but it could not help me]: Filtering compendium | Kirby CMS

Thanks in advance for your help


My doubt: is it relevant that i am using a snippet to do this [and not the controller]?

What does the day parameter contain? It doesn’t make sense to pass a day name to the date() method, it expects a Unix timestamp. So why don’t you just filter by the parameter?

$filter_date = param('filter_date')); 
$collection = $collection->filterBy('my_date_field', 'date ===', $filter_date);

edit: i tried also with entire date but it doesn’t work…

Shoud be date ==, but again, what is stored in the filter_date param now, and I wonder if that works if the date field also contains the time