MySQL查询返回-7到当前日期的+7? [英] MySQL query returning -7 to +7 of current date?
本文介绍了MySQL查询返回-7到当前日期的+7?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可以在日期列等于当前日期的-7至+7的日期列上运行查询.
Is to possible to run a query on a date column where the date is equal to -7 to +7 of the current date.
以今天(12月4日)为例,查询将从11月27日返回到12月11日.
Using today (Dec 4th) as the example the query would return from Nov 27th to Dec 11th.
希望如此.
谢谢
凯伦
推荐答案
当然可以.假设您在列中只有日期(没有时间部分):
Of course. Assuming you have a date only (no time component) in the column:
where datecol >= curdate() - interval 7 day and
datecol <= curdate() + interval 7 day
有或没有时间部分,这都可以工作:
With or without a time component, this will work:
where datecol >= curdate() - interval 7 day and
datecol < curdate() + interval 8 day
请注意,这两个都返回15天的行.
Note that both of these return 15 days of rows.
这篇关于MySQL查询返回-7到当前日期的+7?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文