You need to pass second parameter as FALSE
in select()
so it will not quote the bacticks for STR_TO_DATE(end_date,%d/%m/%Y) AS DATE
$this->db->select("*,STR_TO_DATE(end_date,'%d/%m/%Y') AS DATE",FALSE)
Question
I need a little assistance. I need this query
SELECT *, STR_TO_DATE( end_date, "%d/%m/%Y" ) AS DATE
FROM `resume_experience`
WHERE `resume_id` =1
ORDER BY DATE DESC
to be written in codeigniter active record format. This is what I wrote.
$result = $this->db->select('*,STR_TO_DATE(end_date,%d/%m/%Y) AS DATE')
->from('resume_experience')
->order_by('DATE', "desc")
->where($where)
->get()
->result_array();
return $result;
It is giving me the following error.
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM (resume_experience
) WHERE resume_id
= '1' ORDER BY DATE
desc' at line 2
SELECT *, STR_TO_DATE(end_date, `%d/%m/%Y)` AS DATE FROM (`resume_experience`) WHERE `resume_id` = '1' ORDER BY `DATE` desc
Any help would highly be appreciated.
Thanks and Waiting,
Ahmad
Solution
You need to pass second parameter as FALSE
in select()
so it will not quote the bacticks for STR_TO_DATE(end_date,%d/%m/%Y) AS DATE
$this->db->select("*,STR_TO_DATE(end_date,'%d/%m/%Y') AS DATE",FALSE)
OTHER TIPS
STR_TO_DATE()
requires quotes around the format string:
$this->db->select('*,STR_TO_DATE(end_date,"%d/%m/%Y") AS DATE')