0

In SQL, I might do something like this

"WHERE DATEPART(month, my_date_field) = 8"

to grab the rows where month in my_date_field = 8.

I am unsure how this syntax translates into Yii2. I have

$query = Fees::find();
$fees = $query->all();

How do I use the WHERE clause on the date field within that $query ?

yoyoma
  • 3,336
  • 6
  • 27
  • 42

1 Answers1

0

The query in yii2 allows text in where clause as below

$fees = Fees::find()
    ->where("DATEPART(month, my_date_field) = 8")
    ->all();

You may chain other 'sql functions' like order, group by , limit etc like this as well.

arkoak
  • 2,437
  • 21
  • 35