mySQL dateTime范围查询问题 [英] mySQL dateTime range Query Issue

查看:369
本文介绍了mySQL dateTime范围查询问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个快速的问题。我有一个db的审计表,其中包含一个datetime列。 (即2012-03-27 00:00:00),如果日期在两个日期之间,我正在构建一个mySQL查询返回一组行。



到目前为止,我的查询如下所示:

  SELECT * FROM util_audit WHERE DATED> = DATE 03/15/2012)和日期(03/31/2012); 

如果我只是使用

  SELECT * FROM util_audit WHERE DATED> = DATE(03/15/2012); 

它将返回我所有的记录,因为它们是本周的日期。



我也尝试过:

  SELECT * FROM util_audit WHERE DATED> = '02 / 15 / 2012 00:00:00'AND DATED< = '03 / 31/2012 00:00:00'; 

没有!它会返回零行,当我知道我所有的日期从本月27日到今天。我在这里遗漏了什么吗?为什么它自己工作,但不是当我添加第二个日期?我可能忽略了一些。

解决方案

尝试:

  SELECT * FROM util_audit WHERE`DATED` BETWEEN2012-03-15AND2012-03-31; 


I have a quick question. I'm have a db an audit Table with a datetime column in it. (i.e 2012-03-27 00:00:00) and I'm building a mySQL query to return a set of rows if the date is in between the two dates I'm giving it.

so far my query looks like this:

SELECT * FROM util_audit WHERE DATED >= DATE(03/15/2012) AND DATED <= DATE(03/31/2012);

if I just use

SELECT * FROM util_audit WHERE DATED >= DATE(03/15/2012); 

It'll return all my record because they were dated this week.

I also tried this:

SELECT * FROM util_audit WHERE DATED >= '02/15/2012 00:00:00' AND DATED <= '03/31/2012 00:00:00';

and nothing! It'll return zero rows, when I know I have all of them dated from the 27 of this month to today. Am I missing something here? why does it work on its own, but not when I add the second date?I'm probably overlooking something.

解决方案

Try:

SELECT * FROM util_audit WHERE `DATED` BETWEEN "2012-03-15" AND "2012-03-31";

这篇关于mySQL dateTime范围查询问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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