Search code examples
yii2date-range

Using yii2 date range in active record


i have a date field in my database which has datetype as data type, how can i use active record to fetch data according to specific date range?

$model = ModelName::find()
        ->where(["date"=>"FROM '2015-06-21' TO '2015-06-27' ", "status"=>1])->all();

Solution

  • I think the correct way could be this:

    $model = ModelName::find()->where(['between', 'date', "2015-06-21", "2015-06-27" ])
    ->andWhere(['status'=> 1])->all();