Skip to content

feat: add Query Builder date helpers#10266

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

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

Conversation

@memleakd

@memleakd memleakd commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions github-actions Bot added the 4.8 PRs that target the `4.8` branch. label Jun 1, 2026

@patel-vansh patel-vansh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, this feature can be handy. Looks good. Thanks

@github-actions github-actions Bot added the stale Pull requests with conflicts label Jun 11, 2026
@github-actions

Copy link
Copy Markdown

👋 Hi, @memleakd!

We detected conflicts in your PR against the base branch 🙊
You may want to sync 🔄 your branch with upstream!

Ref: Syncing Your Branch

@memleakd memleakd force-pushed the feat/query-builder-date-helpers branch from f96f54d to e2e6106 Compare June 11, 2026 09:25
memleakd added 2 commits June 12, 2026 10:08
- 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>
Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
@memleakd memleakd force-pushed the feat/query-builder-date-helpers branch from 445e6d6 to 77371cc Compare June 12, 2026 08:12
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. stale Pull requests with conflicts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants