我想显示数据库中过期的产品,该产品的过期日期最多为14天

问题描述 投票:-1回答:1

我想显示一个数据库中的过期产品,该数据库的到期日期最多为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;
}
php database product
1个回答
0
投票

只需将$date变量更改为14天之前,就像这样

//$date=date('Y-m-d');
$date = (new DateTime())->sub(new DateInterval('P14D'))->format('Y-m-d');
© www.soinside.com 2019 - 2024. All rights reserved.