在 mysql 中显示从 now() 到接下来 7 天的记录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4806701/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Show records from now() till next 7 days in mysql
提问by Frank
I want to select rows from the datetime now till 7 days in the future, how can I do this? Read alot about the date function of mysql but cant figure it out, this is the MySQL code:
我想从现在到未来 7 天的日期时间中选择行,我该怎么做?阅读了很多关于 mysql 的日期函数但无法弄清楚,这是 MySQL 代码:
SELECT id, date_format(datum, '%d/%m') AS date,
date_format(datum, '%H:%i') AS time, date
FROM wedstrijden
WHERE date >= now()
ORDER BY datum asc
I have to do something with:
我必须做一些事情:
date >= now() till 7 days further
回答by TehShrike
I would submit that the most elegant way would be:
我认为最优雅的方式是:
WHERE `date` BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL 7 DAY)
Edit: this doc pageis like the most useful thing ever. Bookmark it, because it is totally handy.
编辑:这个文档页面就像有史以来最有用的东西。为它添加书签,因为它非常方便。
回答by John Parker
回答by Kima
What i use to get all the data from 7 days back till now from the database:
我用来从数据库中获取从 7 天到现在的所有数据的方法:
SELECT * FROM wedstrijden WHERE DATE(date_from_table) > CURDATE() + INTERVAL 7 DAY
SELECT * FROM wedstrijden WHERE DATE(date_from_table) > CURDATE() + INTERVAL 7 DAY
回答by markf
Something like:
就像是:
"...WHERE date >= NOW() AND date <= ADDTIME(NOW(), 168:00:00)..."
should accomplish what you're looking for. The 168:00:00 is a bit specific for your needs, ADDTIME takes any datetime format.
应该完成你正在寻找的东西。168:00:00 有点特定于您的需要,ADDTIME 采用任何日期时间格式。