1

I need to return results from database table only where updated_at field is not older than 24h.

Inside my index action I have this code:

$dataProvider = new ActiveDataProvider([
    'query' => SearchStats::find(),
    'pagination' => [
        'pageSize' => 10,
    ],
]);

How can I modify this code to return me results that where inserted / updated in the past 24h hours ?

updated_at is integer, and I am using TimestampBehavior.

arogachev
  • 33,150
  • 7
  • 114
  • 117
offline
  • 1,589
  • 1
  • 21
  • 42

1 Answers1

2

Change your query to:

use yii\db\Expression;

SearchStats::find()
    ->where(['>=', 'updated_at', new Expression('UNIX_TIMESTAMP(NOW() - INTERVAL 1 DAY)')])

Related links:

Community
  • 1
  • 1
arogachev
  • 33,150
  • 7
  • 114
  • 117