duan7664 2016-05-26 06:05
浏览 32
已采纳

如何在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

  • 写回答

1条回答 默认 最新

  • dongxing7318 2016-05-26 06:12
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作