特别说明下:以下统计本周数据时,星期天是作为下周的第一天,而不是本周最后一天,因此你把星期天作为本周最后一天时,你需要在getDate()的基础上减一天,如dateadd('day', -1, getDate())
本周:select * from table where datediff(week,C_CALLTIME,getdate())=0 --C_CALLTIME 为日期字段
本月:select * from table where datediff(Month,C_CALLTIME,getdate())=0 --C_CALLTIME 为日期字段
本季:select * from table where datediff(qq,C_CALLTIME,getdate())=0
前半年1-6,后半年7-12:select * from table where datepart(mm,C_CALLTIME)/7 = datepart(mm,getdate())/7
昨天
select convert(varchar(10),getdate() - 1,120)
明天
select convert(varchar(10),getdate() + 1,120)
最近七天
select * from tb where 时间字段 >= convert(varchar(10),getdate() - 7,120)
随后七天
select * from tb where 时间字段 <= convert(varchar(10),getdate() + 7,120) and 时间字段 >= 时间字段
convert和dateadd函数结合使