Skip to content

Instantly share code, notes, and snippets.

@kimaditiya
Forked from o-shabashov/php.php
Created February 10, 2017 04:26
Show Gist options
  • Select an option

  • Save kimaditiya/6acceecf1131522314ff8a0c4ad8b27a to your computer and use it in GitHub Desktop.

Select an option

Save kimaditiya/6acceecf1131522314ff8a0c4ad8b27a 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