SQL查询从同一天获取记录 [英] SQL query to get records from same day

查看:590
本文介绍了SQL查询从同一天获取记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望找到当前的所有记录。
我有一个字段日期类型为DATE。

I wish to find all records of the current day. I have a field Date of type DATE.

如果我使用

WHERE `Date` = '2011-04-07'

它的作品

但如果我使用:

WHERE  `Date`='CURDATE()'

WHERE  `Date`='NOW()'

它不返回任何结果(实际上有一些)。

it does not return any results (when there actually are some).

如何以正确的格式获取当前日期以使用在我的SQL查询中?

How do I get the current date in the right format to use it in my SQL query?

我正在使用MySQL
而日期最初是使用NOW()输入数据库。

I am using MySQL And the date was originally entered in the database using NOW().

推荐答案

使用

WHERE `Date`=CURDATE()

引号(')用于包装字符串(文本)。

The quotes (') are used to wrap up a string (text).

编辑:我现在可以看到,你说这个值是以 NOW()存储的:它可能还包括一个时间元素。将立即更新答案..

I can see now that you say the value was stored with NOW() : it probably includes a time element too. Will update answer imminently..

这将比较Date字段的日期部分与今天的日期:

This will compare the date part of the Date field to today's date:

WHERE DATE(`Date`)=CURDATE()

这篇关于SQL查询从同一天获取记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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