Yii Framework Forum: Date compare in CDBCriteria (Solved) - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Date compare in CDBCriteria (Solved) Rate Topic: ***** 2 Votes

#1 User is offline   javed alam 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 11-January 11

Posted 07 August 2011 - 03:11 AM

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(select * from tablename where exp_d > now())

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.
0

#2 User is offline   Soumya 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 21-November 10
  • Location:Kolkata, India

Posted 07 August 2011 - 01:51 PM

View Postjaved alam, on 07 August 2011 - 03:11 AM, said:

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(select * from tablename where exp_d > now())

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.'" ');

3

#3 User is offline   javed alam 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 11-January 11

Posted 07 August 2011 - 10:22 PM

*
POPULAR

View PostSoumya, on 07 August 2011 - 01:51 PM, said:

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);

7

#4 User is offline   hemc 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 84
  • Joined: 09-July 12
  • Location:New Delhi

Posted 30 July 2012 - 03:39 AM

thnax for this beautiful question and answer javed.
i was searching the basic for adding such conditions in criteria
Please don't add a reply to say thanks, There is already a +1 button to do same.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users