Cakephp: how to make NOW () work in search mode?

I am trying to get all records with a date greater than now. I tried this, but this does not work:

$all_dates = $this->TourDate->find('all', array('conditions' => array('TourDate.date >=' => 'NOW()'), 'order' => array('TourDate.date ASC')));

If I replaced NOW () with the current date, it will work. Why?

+5
source share
5 answers

I do not use CakePHP, but I'm sure your 'NOW()'process the string and finally you got something like

TourDate.date >= 'NOW()'

Maybe you should just try

array('TourDate.date >= NOW()')

as a value, not for dividing it into key => valuestyle?

+24
source

PHP- istead MySQL-, $conditions = array('begin >' => date('Y-m-d H:i:s')), MySQL 'c' PHPs date() ISO 8601 $conditions = array('begin >' => date('c')).

'begin >' => date('c', strtotime("+4 weeks")), SQL-.

+3

'conditions' => array('TourDate.date >= NOW()')

cakephp NOW(), mysql .

+1

hsz . Cake NOW() 'NOW()'. SQL , hsz.

date('Y-m-d H:i:s') NOW() ( ). ! , hsz .

0

I believe CakePHP removes any SQL functions to prevent SQL injection attacks. As this annoys me, I usually use the date ("Ymd H: i: s").

-1
source

All Articles