0

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

John Conde
  • 207,509
  • 96
  • 428
  • 469
Omicans
  • 521
  • 6
  • 22

2 Answers2

0

STR_TO_DATE() requires quotes around the format string:

$this->db->select('*,STR_TO_DATE(end_date,"%d/%m/%Y") AS DATE')
John Conde
  • 207,509
  • 96
  • 428
  • 469
0

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)

See active record

M Khalid Junaid
  • 60,231
  • 8
  • 78
  • 110