选择查询中的“今天的日期"不起作用 [英] Select query with Date of Today not working

查看:75
本文介绍了选择查询中的“今天的日期"不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从表文档中选择日期为今天的日期.我正在使用Codeigniter. 但是它只显示没有小时的这些文档.我的意思是数据库日期在哪里:2015-06-25 00:00:00.但不会在一个小时的时间显示这些文档-例如:2015-06-25 08:34:00. 如何显示日期"为当前日期的所有文档,而不管是什么时间.

I'm trying to select from table Documents where Date is Today's date. I'm using Codeigniter. But it shows only these documents where there isn't hour. I mean where in database date is: 2015-06-25 00:00:00. But it doesn't display these documents where there is an hour - for example : 2015-06-25 08:34:00. How to display all documents where Date is current date , no matter what is the hour.

<?php
 $date = new DateTime("now");
 
 $curr_date = $date->format('Y-m-d ');

 $this->db->select('*');
 $this->db->from('documents'); 
 $this->db->where('Date', $curr_date);
 $query = $this->db->get();
    return $query->result();

推荐答案

尝试一下

<?php
 $date = new DateTime("now");

 $curr_date = $date->format('Y-m-d ');

 $this->db->select('*');
 $this->db->from('documents'); 
 $this->db->where('DATE(Date)',$curr_date);//use date function
 $query = $this->db->get();
    return $query->result();

MySQL日期功能

这篇关于选择查询中的“今天的日期"不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆