如何得到当日,本周,本月的数据?谢谢大家
有数据表pact
pact_id pact_name begintime endtime
1 经合同 2007-03-15 2007-9-15
2 经合同 2007-08-15 2007-9-18
......
现在我要分别查询今日,本周,本月的数据,应该如何做.
如今天是2007-08-27,选择本月时,也能查询到上面的数据.
谢谢大家
------解决方案--------------------select * from pact where begintime <= convert(varchar(10),getdate(),120) and endtime > = convert(varchar(10),getdate(),120)
select * from pact where datediff(Week , begintime , getdate()) > = 0 and datediff(Week , endtime , getdate()) <= 0
select * from pact where datediff(month , begintime , getdate()) > = 0 and datediff(month , endtime , getdate()) <= 0