Yii2查询get where
Yii2 query get where
我正在尝试执行查询并获取 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
}
我该怎么做?
我找到了这个答案并做了一些非常细微的修改以适应您的情况:
$yesterday = strtotime("-24 hours");
$trucks = Orders::find()->where(['<=', 'created_at', $yesterday])
->orderBy('created_at DESC')->all();
我正在尝试执行查询并获取 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
}
我该怎么做?
我找到了这个答案并做了一些非常细微的修改以适应您的情况:
$yesterday = strtotime("-24 hours");
$trucks = Orders::find()->where(['<=', 'created_at', $yesterday])
->orderBy('created_at DESC')->all();