Question

Below is my Find condition to get records matching <= next 1 hr show timings.

$conditions = array(
    "CONCAT(`showdate`,' ',`hours`,':',`minutes`,':00') <" => "DATE_ADD(NOW(), INTERVAL 1 HOUR)",
    "CONCAT(`showdate`,' ',`hours`,':',`minutes`,':00') >=" => "NOW()");

If run same query in PHPMyAdmin - SQL prompt, its working as below:

SELECT * FROM `showtimes` WHERE CONCAT( `showdate` , ' ', `hours` , ':', `minutes` , ':00' ) < DATE_ADD( NOW( ) , INTERVAL 1 HOUR ) AND CONCAT( `showdate` , ' ', `hours` , ':', `minutes` , ':00' ) >= NOW( ) LIMIT 0 , 30

Above MySQL query is running fine, but when I check with CakePHP Find, its not working.

Below is combination for same:

$conditions = array(
    "CONCAT(`showdate`,' ',`hours`,':',`minutes`,':00') <" => "DATE_ADD(NOW(), INTERVAL 1 HOUR)",
    "CONCAT(`showdate`,' ',`hours`,':',`minutes`,':00') >=" => "NOW()",
    );

pr($conditions);
$this->Showtime->recursive = -1;
$areas = $this->Showtime->find('all',
            array(
                    'conditions' => $conditions,
                    'limit' => $limit,
                    'offset' => $offset,
                    'group' => 'Showtime.id',
                )
            );

pr($areas);

Any help or ideas will be appreciated.

Was it helpful?

Solution

Here is the condition, I found working for me:

$conditions = array("CONCAT(`hours`,':',`minutes`) <=" => date('H:i', strtotime('+1 hour')), "CONCAT(`hours`,':',`minutes`) >=" => date('H:i'));

Hope it helps to the community members !

Suggestions always welcome.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top