phpdatecodeigniterquery-builderstr-to-date

CodeIgniter query builder script to filter rows by date strings stored as m/d/Y


I have a column in a database with a date stored as mm/dd/yyyy. I need to grab all the rows with dates greater than a certain date. (Ex. any date after 01/01/2013). How do I do this using query builder methods?

I have tried:

$this->db->select('DATE_FORMAT(date, '%mm/%dd/%Y') as mydate');
$this->db->where('mydate >','01/01/2013');

Solution

  • $this->db->select("DATE_FORMAT(date, '%m/%d/%Y') as mydate",FALSE);
    $this->db->from('table');
    $this->db->where("DATE_FORMAT(date,'%Y-%m-%d') > '2013-01-01'",NULL,FALSE);