如何从一个月前从数据库获取值忽略当前日期的某些天?

时间:2015-03-16 03:31:50

标签: mysql sql database date select

SELECT user.username, offer.* FROM offer 
INNER JOIN user ON user.userid = offer.userid 
 WHERE offer.date BETWEEN
 (NOW() - INTERVAL 40 DAY) AND NOW()

这项工作很好。它以40天的时间间隔显示记录,当前日期/日期为参考

问题:

我希望记录40天或更长时间的记录,过去40天作为参考。

即。它应该忽略当前日期的前40天,并显示早于该日期的记录。

3 个答案:

答案 0 :(得分:2)

在这种情况下,你可以这样做:

SELECT user.username, offer.* FROM offer 
INNER JOIN user ON user.userid = offer.userid 
WHERE offer.date < (NOW() - INTERVAL 40 DAY)

你非常接近; - )

答案 1 :(得分:2)

SELECT user.username, offer.* FROM offer 
INNER JOIN user ON user.userid = offer.userid 
WHERE offer.date < (NOW() - INTERVAL 40 DAY) 

答案 2 :(得分:2)

那么从现在起不到40天......

SELECT user.username, offer.* FROM offer 
INNER JOIN user ON user.userid = offer.userid 
WHERE offer.date < (NOW() - INTERVAL 40 DAY)