两个日期之间的Mysql选择将无法正常工作

时间:2015-05-30 12:52:50

标签: mysql sql date

我想从表中选择BETWEEN两个日期(date1和date2)。我遇到过这个问题,但我不知道为什么这次不行。我的收据表中只有1行,时间戳为:2015-05-29 22:09:44。 我尝试过这些语法:

SELECT * FROM receipt
WHERE (date BETWEEN 2015-05-22
AND 2015-05-30) //not work even with date_format()

SELECT * FROM receipt
WHERE date > 22-05-2015 AND date < 30-05-2015 //not work even with date_format()

SELECT * FROM receipt
WHERE date > 22-05-2015 //work but when I changed to date > 22-07-2015 it's still select row (my timestamp is may 2015)

2 个答案:

答案 0 :(得分:2)

你可以试试这个:

SELECT * 
FROM receipt
WHERE DATE(`date`) BETWEEN '2015-05-22' AND '2015-05-30'

答案 1 :(得分:0)

SELECT 
  blahblah 
FROM receipt
WHERE thedate >= '2014-12-01 00:00:00' 
  AND thedate <= '2015-05-06 00:00:00'