S
S
Sergey2015-03-29 21:47:36
MySQL
Sergey, 2015-03-29 21:47:36

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

2 answer(s)
O
Oleg Tsvetkov, 2015-03-29
@butteff

$postdb = Posts::find(['login_id' => $id, 'type'=>'update'])
    ->where(['>=', 'some_date_column', new \yii\db\Expression('NOW() - INTERVAL 3 HOUR')])
    ->all();

A
Alexander Alexandrovich, 2015-03-29
@tatu

There is such a function in mysql "between"
Try to use it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question