Date compare in CDBCriteria (Solved)

Hi everybody.

i have a filed exp_d(date data type).

i want to get the records where exp_d > today

in sql this query works fine([color="#8B0000"]select * from tablename where exp_d > now()[/color])

i use this code in yii




$criteria = new CDbCriteria;

$now = new CDbExpression("NOW()");

$criteria->compare('exp_d',$now, false, '>');



but i didn’t get the desire result.

Hi Javed,

    You can use the code as follows.



$criteria = new CDbCriteria;

$now = new CDbExpression("NOW()");

$criteria->addCondition('exp_d > "'.$now.'" ');



Thanks for the tip.




$criteria->addCondition('exp_d > "'.$now.'" ');



didn’t work but this does




$criteria->addCondition('exp_d > '.$now);



thnax for this beautiful question and answer javed.

i was searching the basic for adding such conditions in criteria