CodeIgniter Forums
MySQL DATE_FORMAT with Active Record - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: MySQL DATE_FORMAT with Active Record (/showthread.php?tid=6863)



MySQL DATE_FORMAT with Active Record - El Forum - 03-14-2008

[eluser]Référencement Google[/eluser]
Hi,

How would you do this query using Active Record ?
Code:
SELECT DATE_FORMAT(your_date_field, 'Year: %Y Month: %m Day: %d') AS formated_date FROM your_table;



MySQL DATE_FORMAT with Active Record - El Forum - 03-14-2008

[eluser]mironcho[/eluser]
Hi,
You can try this:
Code:
$this->db->select("DATE_FORMAT(your_date_field, 'Year: %Y Month: %m Day: %d') AS formated_date");
$query = $this->db->get('your_table');



MySQL DATE_FORMAT with Active Record - El Forum - 03-14-2008

[eluser]Référencement Google[/eluser]
Whoooops... just got it !
If it can help somebody:

Code:
function list_all($lang, $limit = FALSE, $offset = FALSE)
    {

        $this->db->select('*');
        $this->db->select("DATE_FORMAT(datetime, '%d.%m.%Y à %H:%i:%s') AS datetime");

        $this->db->where('lang', $lang);
        $this->db->limit($limit);
        $this->db->offset($offset);
        $this->db->order_by('datetime', 'desc');
        $query = $this->db->get('news');

        return $query->result();
    }



MySQL DATE_FORMAT with Active Record - El Forum - 02-20-2009

[eluser]The Wizard[/eluser]
just add a FALSE @ select.
like:

Code:
$this->db->select("DATE_FORMAT(your_date_field, 'Year: %Y Month: %m Day: %d') AS formated_date", FALSE ); // <-- F A L S E