whereDate() and orWhereDate()
The whereDate()
method is a type-safe and secure way to filter DATE or DATETIME fields.
It accepts only valid date strings and automatically rejects malformed, suspicious, or unsafe values.
Method Signature
public function whereDate(string $column, string $value, string $operator = '='): self
public function orWhereDate(string $column, string $value, string $operator = '='): self
Basic Usage
Match a specific date exactly:
$db->whereDate('created_at', '2024-01-01');
$orders = $db->get('orders');
Use comparison operators like >
, <
, !=
etc.:
$db->whereDate('created_at', '2023-12-31', '>');
$orders = $db->get('orders');
Allowed Input and Validation
The $value
must be a valid date or datetime string. Any non-date input will be blocked immediately.
Input | Accepted | Reason |
---|---|---|
'2024-01-01' | ✅ | Valid date format |
'2024-01-01 12:00:00' | ✅ | Valid datetime |
'1 OR 1=1' | ❌ | Blocked – suspected injection |
'NOW()' | ❌ | Use $db->now() instead |
Security Note
All values are strictly validated and passed via prepared statements.
Suspicious strings or invalid formats are not allowed and will throw an exception.
OR Variant
orWhereDate()
behaves the same but adds an OR
clause instead of AND
.