我完全感到困惑,如何在Yii ActiveRecord中比较日期和时间?
我的模型中有此方法:
public static someMethod(){
self::updateAll(['status' => SomeModel::STATUS_ACTIVE], [
'status' => SomeModel::STATUS_ONLINE,
'last_seen_timestamp_no_timezone + 15 minutes < now()'
]);
}
如何在我的updateAll()调用中添加条件:last_seen_timestamp_no_timezone + 15 minutes < now()
?
答案 0 :(得分:2)
您可以使用php:
public static someMethod(){
self::updateAll(['status' => SomeModel::STATUS_ACTIVE], [
'AND',
['status' => SomeModel::STATUS_ONLINE],
['<', 'last_seen_timestamp_no_timezone', date('Y-m-d H:i:s', strtotime('-15 minutes'))]
]);
}