NOW() + INTERVAL 1 DAY -- This time tomorrow CURDATE() - INTERVAL 4 DAY -- Midnight 4 mornings ago
显示3至10小时前(180至600分钟前)询问的mysql问题存储:
SELECT qId,askDate,minuteDiff FROM ( SELECT qId,askDate, TIMESTAMPDIFF(MINUTE,askDate,now()) as minuteDiff FROM questions_mysql ) xDerived WHERE minuteDiff BETWEEN 180 AND 600 ORDER BY qId DESC LIMIT 50; +----------+---------------------+------------+ | qId | askDate | minuteDiff | +----------+---------------------+------------+ | 38546828 | 2016-07-23 22:06:50 | 182 | | 38546733 | 2016-07-23 21:53:26 | 195 | | 38546707 | 2016-07-23 21:48:46 | 200 | | 38546687 | 2016-07-23 21:45:26 | 203 | | ... | | | +----------+---------------------+------------+
的MySQL手册页TIMESTAMPDIFF()。
当心不要CURDATE() + 1在MySQL中使用诸如日期算术之类的表达式。它们不会返回您期望的结果,特别是如果您习惯了Oracle数据库产品。使用CURDATE() + INTERVAL 1 DAY代替。