Get all records between two dates

2019-03-06 09:07发布

问题:

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

回答1:

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);


回答2:

Try this one:

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


回答3:

$this->db->select('*');
    $this->db->from('manual_discount');
    $this->db->where("DATE_FORMAT(created_datetime,'%Y-%m-%d') >= '2018-09-06'",NULL,FALSE);
    $this->db->where("DATE_FORMAT(created_datetime,'%Y-%m-%d') <= '2018-09-06'",NULL,FALSE);

this works fine for me



标签: codeigniter