如何使用 MySQL 在两个日期之间进行查询?

2021-11-20 00:00:00 sql mysql

以下查询:

SELECT * FROM `objects` 
WHERE (date_field BETWEEN '2010-09-29 10:15:55' AND '2010-01-30 14:15:55')

什么都不返回.

我应该有足够的数据来让查询工作.我做错了什么?

I should have more than enough data to for the query to work though. What am I doing wrong?

推荐答案

您的第二个日期在您的第一个日期之前(即,您在 2010 年 9 月 29 日和 2010 年 1 月 30 日之间进行查询).尝试颠倒日期顺序:

Your second date is before your first date (ie. you are querying between September 29 2010 and January 30 2010). Try reversing the order of the dates:

SELECT *
FROM `objects`
WHERE (date_field BETWEEN '2010-01-30 14:15:55' AND '2010-09-29 10:15:55')

相关文章