Answer the question
In order to leave comments, you need to log in
How to pull data from the database for the last 3 hours in yii2 using active record methods?
The database has a datetime column.
I fill it in using the date("Ymd H:i:s") function.
The task is to pull records from the database for the last three hours.
How to do it?
$postdb = Posts::find(['login_id' => $id, 'type'=>'update'])->where(какая-то магия)->All();
Answer the question
In order to leave comments, you need to log in
$postdb = Posts::find(['login_id' => $id, 'type'=>'update'])
->where(['>=', 'some_date_column', new \yii\db\Expression('NOW() - INTERVAL 3 HOUR')])
->all();
There is such a function in mysql "between"
Try to use it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question