Date Ranges with DateFilter
Date Ranges with DateFilter
~12 Min. Lesezeit Zuletzt aktualisiert am August 8, 2026
DateFilter is SPECIALIZED for date/time fields – MORE ERGONOMIC than RangeFilter for createdAt, with its OWN, more descriptive operator names.
Applying DateFilter
use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
#[ApiFilter(DateFilter::class, properties: ['createdAt'])]
The operators at a glance
| Query parameter | Meaning |
|---|---|
createdAt[after]=2026-08-01 | Created ON OR AFTER this date |
createdAt[before]=2026-08-31 | Created ON OR BEFORE this date |
createdAt[strictly_after]=... | Created AFTER this date, the date ITSELF EXCLUDED |
createdAt[strictly_before]=... | Created BEFORE this date, the date ITSELF EXCLUDED |
Querying a month's projects
curl -k 'https://localhost/api/projects?createdAt[after]=2026-08-01&createdAt[before]=2026-08-31'TWO combined DateFilter parameters EFFECTIVELY produce a date range – MORE READABLE than the equivalent RangeFilter syntax with full ISO 8601 timestamps.
Handling NULL values
For NULLABLE date fields (not relevant for US right now, since createdAt is ALWAYS set), DateFilter additionally offers an [include_null_before]/[include_null_after] configuration, to control whether entries WITHOUT a date show up in range queries.
All of this block's filters working together
curl -k 'https://localhost/api/projects?name=Project&priority[gte]=3&createdAt[after]=2026-08-01&order[priority]=desc&itemsPerPage=5'FIVE independent mechanisms (text search, numeric range, date range, sorting, page size) in ONE single request, WITHOUT a SINGLE line of custom filter code – the COMPLETE payoff of block 4.
Tipp: Chapter 35 shows how filters can be COMBINED and what a CUSTOM filter class looks like, for cases the built-in filters CAN'T handle (e.g. a full-text search across MULTIPLE fields with ONE parameter).