I have a query in CakePHPthat has a stored "datetime" field called DropIn.drop_in_time
. I would like to only "find" entries where the DropIn.drop_in_time is > NOW()
but am having trouble getting it to do that.
The condition DropIn.drop_in_time >' => 'NOW()
didn't get the right results in the query below. Is there a better way to do it?
$requests = $this->DropIn->find('all', array(
'conditions' => array('DropIn.drop_in_time >' => 'NOW()', 'or' => array(array('DropIn.user_id' => $this->Auth->user('id')), array('DropIn.id' => $drop_in_ids))),
'order'=>array('DropIn.created'=>'DESC')));
If you separate the value as 'DropIn.drop_in_time' => 'NOW()'
, 'NOW()'
is taken to mean the literal value string "NOW()"
. Just write it as one SQL fragment instead: 'DropIn.drop_in_time > NOW()'
. Alternatively, use 'DropIn.drop_in_time >' => date('Y-m-d H:i:s')
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With