从mysql中的当前日期选择当前日期和3个月之间的日期 [英] select dates that are between current date and 3 month from the current date in mysql
本文介绍了从mysql中的当前日期选择当前日期和3个月之间的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想选择当前日期和3个月之前的所有日期. 我尝试使用此查询,但无法正常工作.
I want to select all dates that are between the current date and 3 months before. I tried using this query but it isn't working right.
$sql = mysql_query("
SELECT *
FROM date
WHERE d_date BETWEEN NOW() AND NOW() - INTERVAL 3 MONTH
");
请帮助您编写正确的语法.
Please if you could help me write the right syntax.
推荐答案
您需要交换赏金,它将起作用:
You need to swap your bounaries, and it will work:
SELECT * FROM date
WHERE d_date BETWEEN now() - INTERVAL 3 MONTH AND now()
例如,此查询返回true( SQLFiddle ):
For example, this query returns true (SQLFiddle):
SELECT (now() - interval 1 month)
BETWEEN now() - interval 3 month AND now()
这篇关于从mysql中的当前日期选择当前日期和3个月之间的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文