select * from yourtable where datediff(yy,日期字段,getdate())>=0 and datediff(yy,日期字段,getdate()) < =5
select * from tableName where datediff(day,lasttime,getdate())<=5
select * from tableName where datediff(day,lasttime,getdate())>=0 and datediff(day,lasttime,getdate())<=5
显示:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'getdate())<=5' at line 1
不中数据库中有不同的内置函数.这样死般.
肯定不行啦!
你刚又没说你的是mysql啊.
查查mysql的内置函数..
mysql手册查date_sub函数
mysql> select date_sub(curdate(),interval 1 day);
+------------------------------------+
| date_sub(curdate(),interval 1 day) |
+------------------------------------+
| 2006-06-19 |
+------------------------------------+
1 row in set (0.09 sec) mysql> select date_sub('2006-06-04',interval 1 day);
+---------------------------------------+
| date_sub('2006-06-04',interval 1 day) |
+---------------------------------------+
| 2006-06-03 |
+---------------------------------------+
1 row in set (0.00 sec)
select * from Table where datediff(d,lasttime,getdate())<=5 and datediff(d,lasttime,getdate()) >0