Reputation: 2600
Whats the right way to use BETWEEN in Yii Framework?
Code:
...
$criteria = new CDbCriteria;
$criteria->condition = 'datetime BETWEEN '.$datetimemin.' AND '.$datetimemax;
$user = Users::model()->find($criteria);
...
Error:
SQL: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '07:10:10 AND 2011-10-10 13:10:10)' at line 1.
Upvotes: 0
Views: 8496
Reputation: 133
most correct
$criteria->addBetweenCondition('attributeName', 'value1', 'value2');
Upvotes: 12
Reputation: 46060
I don't know the "correct" way to do it in Yii.
But the error is because the dates need to be quoted.
$criteria->condition = 'datetime BETWEEN "'.$datetimemin.'" AND "'.$datetimemax.'"';
Upvotes: 2