试一试
select * from `table` where `yourfield` >= DATE_SUB(CURDATE(), INTERVAL 3 MONTH)
几天之内,年份请见下面的示例。
DATE_SUB(CURDATE(), INTERVAL 15 DAY) /*For getting record specific days*/
DATE_SUB(CURDATE(), INTERVAL 1 YEAR) /*for getting records specific years*/
BETWEEN DATE_SUB( CURDATE( ) ,INTERVAL 6 MONTH ) AND DATE_SUB( CURDATE() ,INTERVAL 3 MONTH )
/* For Getting records between last 6 month to last 3 month
最好进行比较
`date`< DATE(NOW() - INTERVAL 30 DAY)
DATEDIFF(date,NOW()) = -30
$result = mysql_query("SELECT * FROM all_count WHERE `date`< DATE(NOW() - INTERVAL 30 DAY) and member ='000002'");
正如您在此处的文档中所看到的,MySQL中的DATEDIFF
函数可以告诉您第一个日期与第二个日期之间的天数差异。
您的查询仅选择所有差异恰好为30天的行,而不是那些最多30天前的行。因此,有可能20天前的日期的行数比30天前的日期更高。您最可能想要的是:
SELECT * FROM all_count WHERE DATEDIFF(date,NOW()) >= -30 and member ='000002'