我必须比较 mysql 中的日期,例如:
select col1,col2 from table where date <= '2011-12-24' (present date)
但这只输出小于“2011-12-24”的所有日期。
最佳答案
我怀疑你的问题是你的 date
column 是时间戳,但您将其与日期进行比较。完成后,您的 2011-12-24
转换为 2011-12-24 00:00:00.0000
因此任何有 2011-12-24
的东西合理的时间是在这一点之后。在你的情况下,我会使用
select col1,col2 from table where my_date < '2011-12-25' (present date + 1 day)
或者,如果您坚持使用 <=
然后
select col1,col2 from table where date(my_date) <= '2011-12-24' (present date)
关于mysql - 如何在 MySql 中进行日期时间比较时小于等于?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8623996/