Created
May 29, 2016 22:49
-
-
Save o-shabashov/c5f866b5653f99a6ec3d32663056587a to your computer and use it in GitHub Desktop.
Yii2 ActiveRecord get all records for last %interval%
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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