Skip to content

feat: add Query Builder date helpers#10266

Open
memleakd wants to merge 1 commit into
codeigniter4:4.8from
memleakd:feat/query-builder-date-helpers
Open

feat: add Query Builder date helpers#10266
memleakd wants to merge 1 commit into
codeigniter4:4.8from
memleakd:feat/query-builder-date-helpers

Conversation

@memleakd
Copy link
Copy Markdown
Contributor

@memleakd memleakd commented Jun 1, 2026

Description

This proposes adding a small set of Query Builder helpers for filtering by parts of a date/datetime column:

$builder->whereDate('created_at', '2026-01-31');
$builder->whereYear('created_at', 2026);
$builder->whereMonth('created_at', 1);
$builder->whereDay('created_at', 31);

The matching OR variants are included as well: orWhereDate(), orWhereYear(), orWhereMonth(), and orWhereDay().

The main goal is to make a common query easier to write without asking users to remember the right SQL function for each database driver. The builder compiles the expression for the active driver, while still binding values and protecting identifiers by default.

A few details are documented explicitly:

  • supported comparison operators can be added to the field name, like whereDate('created_at >=', '2026-01-01')
  • null values use IS NULL / IS NOT NULL
  • arrays and subqueries are not accepted for these helpers
  • for large indexed timestamp columns, a range condition may still be more efficient

Tests cover the shared builder behavior, driver-specific SQL output, invalid inputs, DateTimeInterface values, grouped/or conditions, aliases before from(), and a live database query.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

- Add whereDate(), whereYear(), whereMonth(), and whereDay()
- Add OR variants for date-part WHERE clauses
- Compile date-part expressions per database driver
- Document supported operators, null handling, escaping, and index caveats
- Add builder and live database coverage

Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
@github-actions github-actions Bot added the 4.8 PRs that target the `4.8` branch. label Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.8 PRs that target the `4.8` branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant