Reputation: 1125
I would like to fetch a row which comes in a particular date range
My query:
SELECT * FROM `table` WHERE ((s_tdate <= '2016-05-26' OR `e_expiredate` >= '2016-05-26') OR (`s_tdate` <= '2017-09-11' AND `e_expiredate` >= '2017-09-11') OR (`s_tdate` >= '2016-05-26' AND e_expiredate <='2017-09-11'))
$this->db->select(*);
$this->db->where("((s_tdate <='$start_date' AND e_expiredate >= '$start_date')");
$this->db->or_where("(s_tdate <='$end_date' AND e_expiredate >='$end_date')");
$this->db->or_where("(s_tdate >='$start_date' AND e_expiredate <='$end_date'))");
$query = $this->db->get('table');
Am getting no result.
Please help
Upvotes: 0
Views: 67
Reputation: 1091
put OR conditions in between ..
e.g. (s_tdate <= '2016-05-26' AND e_expiredate >= '2016-05-26') OR (s_tdate <= '2017-09-11' AND e_expiredate >= '2017-09-11') OR (s_tdate >= '2016-05-26' AND e_expiredate <='2017-09-11')
Please use this..
Basically it will give query like s_tdate and e_expiredate in given range and provide row which comes in a particular date range
$this->db->select(*);
$this->db->where("s_tdate BETWEEN $start_date AND $end_date");
$this->db->where("e_expiredate BETWEEN $start_date AND $end_date");
$query = $this->db->get('table');
Upvotes: 1