我想获取特定日期范围内的行
我的查询:
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');
没有结果。
请帮忙
答案 0 :(得分:1)
将 OR 条件置于......
之间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')
请使用此..
基本上它会在给定范围内提供类似s_tdate和e_expiredate的查询,并提供特定日期范围内的行
$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');