Date Range Filters
Cumulative date-range filter tabs built with where_raw(), plus the search bar's own quick date-range presets for date/datetime columns.
Cumulative range tabs with where_raw()
None of the usual relative-date buckets - "this week", "this month", "last 6 months" - have a "field OP value" shape that where() can express; CURDATE(), INTERVAL, and YEARWEEK() are MySQL functions, not bindable literals. where_raw($condition, $tab = null) is the tool for this - each tab is its own independently-signed raw SQL condition.
$xcrud->where_raw('DATE(paymentDate) = CURDATE()', 'Today');
$xcrud->where_raw('DATE(paymentDate) = CURDATE() - INTERVAL 1 DAY', 'Yesterday');
$xcrud->where_raw('YEARWEEK(paymentDate, 1) = YEARWEEK(CURDATE(), 1)', 'This Week');
$xcrud->where_raw(
'YEAR(paymentDate) = YEAR(CURDATE()) AND MONTH(paymentDate) = MONTH(CURDATE())',
'This Month'
);
$xcrud->where_raw('paymentDate >= CURDATE() - INTERVAL 6 MONTH', 'Last 6 Months');
These are deliberately nested/cumulative, not a strict mutually-exclusive partition - "This Week" is a subset of "This Month", which is a subset of "Last 6 Months", the same way a "Last 7 days / Last 30 days / Last 6 months" filter usually works elsewhere. A strict partition sounds cleaner but has a real edge case: early in a calendar month, "this month but not in the last two calendar weeks" can be an empty range outright. Nested ranges avoid that and match what a visitor actually expects clicking "This Month" - everything from this month, not everything from this month except what's more recent.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$condition | string | - | Raw SQL condition, inserted verbatim (parenthesized). Trusted, developer-authored SQL only - never build it from request input. |
$tab | string|null | null | Tab label. Omit for a permanent base filter instead of a switchable tab. |
The search bar's own quick date-range presets
Separately from filter tabs, the basic search bar has its own JS-side convenience for date/datetime columns. Open the "Columns (n)" panel next to the simple search box - the same panel used to pick which columns the simple search covers - and any date/datetime column's own checkbox has a quick-range mini panel underneath it: a preset dropdown (Any time / Today / Yesterday / This Week / This Month / This Year / Custom range) plus an editable from/to date pair, populated by whichever preset is picked but still adjustable afterward for fine-tuning.
This is a pure client-side convenience for filling in a date range quickly - no PHP call is needed to enable it, every date/datetime column gets it automatically. It's tracked separately from the Advanced Search panel's own condition rows, but both are combined into the same filter request when the grid reloads, so a quick date range and an advanced condition can be active together.