Skip to content

Instantly share code, notes, and snippets.

@o-shabashov
Created May 29, 2016 22:49
Show Gist options
  • Save o-shabashov/c5f866b5653f99a6ec3d32663056587a to your computer and use it in GitHub Desktop.
Save o-shabashov/c5f866b5653f99a6ec3d32663056587a to your computer and use it in GitHub Desktop.
Yii2 ActiveRecord get all records for last %interval%
<?php
$interval = 'DAY';
//$interval = 'WEEK';
//$interval = 'MONTH';
$brands = BrandExt::find()
->where([
'between',
'brand.created_at',
new Expression(sprintf('date_sub(utc_timestamp, interval 1 %s)', $interval)),
new Expression('utc_timestamp')
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment