I have a datetime
field in my model. In a query I want to select all rows created on a specific day/date (the time doesn't matter). What is the simplest way of doing that in CakePHP 3.8 ?
Asked
Active
Viewed 790 times
1

randomUserName
- 17
- 1
- 5
1 Answers
1
Per other answers, use of a custom function to cast the column with MySQL DATE() may slow your query down at scale. Besides, there's probably nothing simpler than plain arrays to build conditions:
$query = $this->YourTable->find()
->where([
'date_field >=' => '2020-01-01 00:00:0', // Or pass a Time() object..
'date_field <' => '2020-01-02 00:00:00',
]);
This kind of stuff is covered in the Query Builder docs.

Andy Hoffner
- 3,267
- 2
- 21
- 22
-
Nice, thanks. And I used the default PHP DateTime object to get today and tomorrow at midnight. – randomUserName Apr 26 '20 at 08:35