MySQL Yii PHP 框架的 BETWEEN 子句

MySQL BETWEEN clause with Yii PHP framework

使用 Yii PHP 框架,我生成以下查询

SELECT * FROM `purchases` WHERE (date BETWEEN '2013-12-31' AND '2015-01-01')

使用此代码

$exportYear = "2014";
$criteria = new CDbCriteria();
$criteria->addBetweenCondition("date", ((int)$exportYear - 1) . "-12-31", ((int)$exportYear + 1) . "-01-01");
$purchases = Purchase::model()->findAll($criteria);

我真正需要的是 2014 年发生的所有 'purchases'。前一分钟或后一分钟都没有。需要将 addBetweenCondition 行更改为什么才能完成此操作?

SELECT * FROM `purchases` 
WHERE date BETWEEN '2014-01-01' AND '2014-12-31'

BETWEEN 运算符包含在内。

如果列类型是 DATE,请使用 '2014-01-01' AND '2014-12-31'

$exportYear = "2014";
$criteria = new CDbCriteria();
$criteria->addBetweenCondition("date", $exportYear . "-01-01", $exportYear . "-12-31");
$purchases = Purchase::model()->findAll($criteria);

如果列类型是 DATETIME 使用 '2014-01-01 00:00:00' AND '2014-12-31 23:59:59'

$exportYear = "2014";
$criteria = new CDbCriteria();
$criteria->addBetweenCondition("date", $exportYear . "-01-01 00:00:00", $exportYear . "-12-31 23:59:59");
$purchases = Purchase::model()->findAll($criteria);