尝试执行查询并获取其中created_at不大于24小时的项目
我试过了
$trucks = Orders::find()
->where(["created_at"=>not more than 24 hrs ]) //stuck here
->orderBy(['created_at' => SORT_DESC])->all();
Nb:Created_at在unix时间戳中。
在通常的php中它将相当于
$created_at= 1500373706; // time order was created
if ((time() - $created_at) > 86400) {
//Dont get these
} else {
//Get these
}
我该怎么做?
答案 0 :(得分:0)
我找到了这个答案并做了一些非常小的修改以适合您的情况:How to compare Dates from database in Yii2
$yesterday = strtotime("-24 hours");
$trucks = Orders::find()->where(['<=', 'created_at', $yesterday])
->orderBy('created_at DESC')->all();