Using yii2 date range in active record

Nishu PTG picture Nishu PTG · Jun 28, 2015 · Viewed 16.9k times · Source

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();

Answer

scaisEdge picture scaisEdge · Jun 28, 2015

I think the correct way could be this:

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