Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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();
like image 706
Pingu Kutu Avatar asked Jun 28 '15 06:06

Pingu Kutu


1 Answers

I think the correct way could be this:

$model = ModelName::find()->where(['between', 'date', "2015-06-21", "2015-06-27" ])
->andWhere(['status'=> 1])->all();
like image 116
ScaisEdge Avatar answered Nov 13 '22 23:11

ScaisEdge