Hi,
I’m having trouble using the Query builder with the MySQL DATE_FORMAT function.
for instance, if I’m building a query like this:
$month_year = new \yii\db\Expression("DATE_FORMAT(`news_date`, '%Y-%m')");
$months = NewsItem::find()
->select($month_year)
->column();
for some reason, Yii2 quotes the format string, like so:
SELECT DATE_FORMAT(`NewsDate`, `'%Y-%m')`
note the syntax-breaking backticks around:
'%Y-%m')
has anyone successfully used DATE_FORMAT with Query builder?
I can, and will use straight SQL here, but I thought I’d ask the Yii community about it.
-Charlie