Answer the question
In order to leave comments, you need to log in
How to use to_char in Yii2?
SELECT to_char(events.date_start, 'MM') AS month_start
FROM "events"
WHERE "event_id"=13;
Event::find()->select('to_char(events.date_start, \'MM\') AS month_start)->where(["event_id"=>13])->one()
ERROR: syntax error (example position: \"AS\")\nLINE 1: to_char(events.date_start, \"'MM')\" As
Answer the question
In order to leave comments, you need to log in
When an Expression object is embedded within a SQL statement or fragment, it will be replaced with the $expression property value without any DB escaping or quoting. For example,
$expression = new Expression('NOW()');
$now = (new \yii\db\Query)->select($expression)->scalar(); // SELECT NOW();
echo $now; // prints the current date
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question