CodeIgniter Forums
this->db->select contain function - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter Archived (from EllisLab) (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: this->db->select contain function (/thread-37864.html)



this->db->select contain function - El Forum - 01-23-2011

[eluser]Unknown[/eluser]
Code:
$this->db->select("*, DATE_FORMAT(news_time,'%d/%m/%Y') AS vn_date,DATE_FORMAT(news_time,'%Hh%i\'%s\"') AS vn_clock,CASE WHEN DATE_FORMAT(news_time,'%Hh%i\'')>type_time THEN false ELSE true END AS is_ontime",false)
I want to break news_time column into date part and clock part so I use 2 DATE_FORMAT function but it causes an error:
Code:
SELECT *, DATE_FORMAT(news_time, '%d/%m/%Y') AS vn_date, '%Hh%i\'%s"') AS vn_clock, CASE WHEN DATE_FORMAT(news_time, '%Hh%i\'')>type_time THEN false ELSE true END AS is_ontime
We can see that 2 functions DATE_FORMAT is not recognized corectly, to avoid this I have to use an trick:
Code:
$this->db->select("*, DATE_FORMAT(news_time,'%d/%m/%Y') AS vn_date,CASE WHEN true THEN DATE_FORMAT(news_time,'%Hh%i\'%s\"') END AS vn_clock,CASE WHEN DATE_FORMAT(news_time,'%Hh%i\'')>type_time THEN false ELSE true END AS is_ontime",false)