Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我将文章的数据时间存储在我的 mysql 表中,当他将从商店过期时,需要我查询在哪里选择它们将在 3 小时之前过期的文章
有任何想法吗?
采用INTERVAL
INTERVAL
SELECT * FROM articles WHERE expires BETWEEN NOW() AND NOW() + INTERVAL 3 HOUR
用于BETWEEN检查过期时间是 (1) 在未来(过滤掉已经过期)和 (2) 在接下来的 3 小时内
BETWEEN
您可以尝试以下方法:
SELECT * from `table` where TIMESTAMPDIFF(MINUTE, `date_field`, NOW)<180;