根据date_received
列,我试图将每周的记录假设为星期一作为一周的第一天。
此原始查询的等效活动记录查询应该是什么?
$week = $connection->createCommand('SELECT * FROM dts_document WHERE date_received > DATE_SUB(NOW(), INTERVAL 1 WEEK)');
我尝试了以下操作,但它返回了整个记录。
$week = DtsDocument::find()->where(['>','date_received', 'DATE_SUB(NOW(), INTERVAL 1 MONTH)'])->count();
答案 0 :(得分:2)
用yii\db\Expression包裹DATE_SUB
部分以防止引用:
use yii\db\Expression;
...
$week = DtsDocument::find()
->where(['>', 'date_received', new Expression('DATE_SUB(NOW(), INTERVAL 1 MONTH)')])
->count();