if you use SQL Server, you can try (assume your table name is "table1" and the date field is "datefield"): 最近1天: select * from table1 where datediff(day,datefield,getdate()) = 0 最近2天: select * from table1 where datediff(day,datefield,getdate()) <= 1 and datediff(day,datefield,getdate()) >=0 最近3天: select * from table1 where datediff(day,datefield,getdate()) <= 2 and datediff(day,datefield,getdate()) >= 0 最近一个星期: select * from table1 where datediff(day,datefield,getdate()) <= 6 and datediff(day,datefield,getdate()) >= 0
|
注意:
mysql中,只能比较天数,故第一个参数不用写,如:
select * from urlcontent where DateDiff(IR_URLDATE,CURRENT_DATE) <20