加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – STR_TO_DATE在我的查询中不起作用

发布时间:2020-12-13 18:13:42 所属栏目:PHP教程 来源:网络整理
导读:我在数据库中有日期字段,有varchar数据类型.现在我必须将日期与当前日期进行比较,但由于数据类型(varchar)结果不正确. 我不想更改数据库中的数据类型,所以如何在codeigniter中查询? 在我的数据库中,日期的格式为30/11/2015 我目前的查询: //here vd is tab
我在数据库中有日期字段,有varchar数据类型.现在我必须将日期与当前日期进行比较,但由于数据类型(varchar)结果不正确.

我不想更改数据库中的数据类型,所以如何在codeigniter中查询?

在我的数据库中,日期的格式为30/11/2015

我目前的查询:

//here vd is table field(one column).

    $cd = date('d/m/Y');//current date

    $this->db->where("date_format(STR_TO_DATE(vd,'%d/%m/%Y'),'%d/%m/%Y') >",$cd); //comparing date with current date
    $query =$this->db->get('warranty');

By using above query it is just comparing the date not month and year. So it is returning those record which date is greater than today’s date.

但正确的结果不会来……

试试这可能会对你有所帮助:
$cd = date('Y-m-d');

$this->db->where("date_format(STR_TO_DATE(vd,'%Y-%m-%d') >",$cd);
$query =$this->db->get('warranty');

如果在查询中使用date_format,则需要更改日期格式,而是以相同格式更改可能是因为它不起作用.尝试以Y-m-d格式进行更改和比较.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读