1

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 ?

1 Answers1

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