简体   繁体   English

MYSQL日期比较不起作用

[英]MYSQL date comparison not working

I have column in table with type as timestamp, I have 2 records in database one with value "2014-07-12 23:10:15" and other with "2013-06-01 01:10:12" 我在表中的列的类型为时间戳,我在数据库中有2条记录,其中一条的值为“ 2014-07-12 23:10:15”,另一条的值为“ 2013-06-01 01:10:12”

And now quering table like but i am returned with empty result : 现在查询表,但我返回空结果:

SELECT comments.* FROM tbl_product_comments as comments WHERE DATE(comments.created_date) BETWEEN 2010-06-01 AND 2014-07-13

And Also this way, but again getting empty result 而且也这样,但再次得到空结果

SELECT comments.* FROM tbl_product_comments as comments WHERE DATE(comments.created_date) > 2010-06-01 AND DATE(comments.created_date) < 2014-07-13

Can any one please tell me, why i am not getting result and what will be the correct query. 谁能告诉我,为什么我没有得到结果,什么是正确的查询。

Thanks.. 谢谢..

Enclose your date literals with quotes. 日期文字应使用引号引起来。

 BETWEEN '2010-06-01' AND '2014-07-13'

Your original code is being parsed as arithmetic expressions. 您的原始代码被解析为算术表达式。

2010-06-01 = 2003 2010-06-01 = 2003

2014-07-13 = 1994 2014-07-13 = 1994

Example. 例。 This returns data: 这将返回数据:

select * from tab where 2009 between 2010-01-01 and 2014-01-01

evaluates to 评估为

select * from tab where 2009 between 2008 and 2012

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM