find() using date field

Currently, I’m using code form the guide to get all rows from table:

$query = Fees::find();

$fees = $query->all();

I can see that there is a “where” method on the find(), but I’m unsure what the syntax would be to query a date field for a specific month ?

Ie, in SQL, it would be something like "WHERE DATEPART(month, MY_DATETIME) = 8"

How do I translate that to Yii2 find()->where ?

You can put a string in the where function :




$fees = Fees::find()->where('WHERE DATEPART(month, :date) = 8')->params(['date' => $date])->all();



doc : http://www.yiiframework.com/doc-2.0/yii-db-query.html