我正在嘗試?yán)L制包含客戶報(bào)告的圖表,并且我想過(guò)濾掉因非營(yíng)業(yè)日而關(guān)閉的多天商店。我還有一個(gè)過(guò)濾日期從和到。if( $dateFrom != null ) : $dateFrom .= ' 00:00:01'; $this->db->where('created >=', $dateFrom); endif; if( $dateTo != null ) : $dateTo .= ' 23:59:59'; $this->db->where('created <=', $dateTo); endif;我正在嘗試找出如何添加多天的額外過(guò)濾器。所以我目前有類似的東西,但它不起作用。$this->db->where("created BETWEEN '2020-01-01 00:00:01' AND '2020-01-25 23:59:59'"); $this->db->where("created BETWEEN '2020-01-26 00:00:01' AND '2020-04-05 23:59:59'"); $this->db->where("created BETWEEN '2020-04-06 00:00:01' AND '2020-04-25 23:59:59'");$this->db->where("created BETWEEN '2020-04-26 00:00:01' AND '2020-06-27 23:59:59'");$this->db->where("created BETWEEN '2020-06-28 00:00:01' AND '2020-08-29 23:59:59'");$this->db->where("created BETWEEN '2020-08-30 00:00:01' AND '2020-12-12 23:59:59'");$this->db->where("created BETWEEN '2020-12-13 00:00:01' AND '2020-12-19 23:59:59'");$this->db->where("created BETWEEN '2020-12-20 00:00:01' AND '2020-12-31 23:59:59'");所以我只是想弄清楚如何從日期和日期中過(guò)濾除設(shè)置過(guò)濾器之外的天數(shù)。是否有解決方法或任何修復(fù)?
2 回答

Qyouu
TA貢獻(xiàn)1786條經(jīng)驗(yàn) 獲得超11個(gè)贊
您可以將所有特殊日期放入一個(gè)數(shù)組中,如下所示:
$exceptions = ['2020-04-26', '2020-04-27']; // And so on
然后捕獲/定義您的日期范圍:
$dateFrom = $some_source_of_data; $dateTo = $some_source_of_data2;
然后:
$this->db->where("DATE(created) BETWEEN DATE('{$dateFrom}') AND DATE('{$dateTo}')"); $this->db->where("DATE(created) NOT IN (".implode(',', $exceptions).")");
- 2 回答
- 0 關(guān)注
- 174 瀏覽
添加回答
舉報(bào)
0/150
提交
取消