我想显示一个数据库中的过期产品,该数据库的到期日期最多为14天。下面的代码仅显示有效期限为1天的产品。
我如何修改代码以也显示到期前14天的产品?
public function out_of_date(){
//$date=date('Y-n-j');
$date=date('Y-m-d');
$this->db->select('a.expeire_date as exp_date,a.*,b.*,c.*');
$this->db->from('product_purchase_details a');
$this->db->join('product_information c','c.product_id=a.product_id');
$this->db->join('view_m_total_batch_stock b','b.batch_id=a.batch_id');
$this->db->where('b.stock >',0);
$this->db->where('a.expeire_date <=', $date);
$this->db->group_by('b.batch_id');
$query = $this->db->get();
if ($query->num_rows() > 0) {
return $query->result_array();
}
return false;
}
只需将$date
变量更改为14天之前,就像这样
//$date=date('Y-m-d');
$date = (new DateTime())->sub(new DateInterval('P14D'))->format('Y-m-d');