如何在codeigniter上获取具有过期日期的数据

Hello guys i am making search form with voucher code.

I have done about the search with this code :

controller :

function voucher(){
    $voucher = $this->input->GET('voucher');
    $data['search'] = $this->Voucher_m->check_voucher($voucher);
    $this->load->view('/VENDOR/'.country_code.'/Voucher',$data);
}

and this is the model :

function check_voucher($voucher){
    $this->db->join("uhd_restaurant" , "uhd_voucher.restaurant_id = uhd_restaurant.restaurant_id");
    $this->db->where('voucher_code',$voucher);
    $query = $this->db->get('uhd_voucher');
    return $query->result();
}

this is my simple view for my search code :

<?php
if($search!=NULL){
    echo "voucher dapat di gunakan";
}else{
echo "vocher tidak dapat di gunakan";

} ?>

There is no problem on search form, and i can view it. The problem is, when i search the code voucher, but if the expiry date of the voucher has expired, the search form will echo "Sorry, your voucher has expired"

The expiry date of the voucher, i have set it on my database. guys can u help me how to set the expire code?

thank you

You can achieve this in two ways

1) Mysql method:-

 SELECT DATEDIFF('2014-11-30','2014-11-29') AS DiffDate

2) php method:-

   $now = strtotime("2016-05-30"); // or your date as well
   $your_date = strtotime("2016-05-27");
   $datediff = $now - $your_date;
   $dateDiff = floor($datediff/(60*60*24));

Use current date and database date here and put an if condition in the view file to check the remaining days.

You can also use datediff() function in the where clause like below:-

MySQL DateDiff in Where clause?

MySql - get days remaining