Search code examples
codeigniter

Get all records between two dates


How can i fetch all records between two date field dates in mysql table.Am using code igniter for my application.

Am entering start date and end date from date picker , need to fetch all rowas >= startdate and <= end date

my code:-

 $this->db->where('start_date <= ',$start_date);
 $this->db->where('end_date >= ',$end_date);

My query :- SELECT * FROM table WHERE start_date <= '2016-04-13' AND end_date >= '2016-04-19'

This is fetching only one row from table.

Please help


Solution

  • U need to do something like this...

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