【问题标题】:MYSQL date comparison not workingMYSQL 日期比较不起作用
【发布时间】:2014-07-13 07:50:30
【问题描述】:

我在表中有类型为时间戳的列,我在数据库中有 2 条记录,其中一条的值为“2014-07-12 23:10:15”,另一条的值为“2013-06-01 01:10:12”

现在查询表,但我返回空结果:

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

也是这样,但再次得到空结果

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

谁能告诉我,为什么我没有得到结果以及正确的查询是什么。

谢谢..

【问题讨论】:

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

标签: php mysql database date


【解决方案1】:

用引号将您的日期文字括起来。

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

您的原始代码被解析为算术表达式。

2010-06-01 = 2003

2014-07-13 = 1994

示例。这将返回数据:

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

评估为

select * from tab where 2009 between 2008 and 2012

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多