Sql Server中询问当天,方今八日,本周,上月,近年来叁个月,前年的数目标sql语句

最近一个月,此时不能用 datediff 差值为7,from T,最近一个月,此时不能用 datediff 差值为7,datediff只表示间隔数

select * from T_news where datediff(day,addtime,getdate())=0

近日三个月 *select \ from T_news WHERE (DATEPART(yy, addtime) =
DATEPART(yy, GETDATE())) 
AND ((DATEPART(mm, addtime) = DATEPART(mm, GETDATE())) OR
(31-DATEPART(DD,addtime)+DATEPART(DD, GETDATE()))<=31)

多年来叁个月:

三天 select \ from T_news where
datediff(day,addtime,getdate())<= 2 and
datediff(day,addtime,getdate())>= 0*

近日八日:

留意:此时无法用 datediff 差值为七,因为,datediff只表示间隔数

本周:

专注:此时不可能用 datediff 差值为七,因为,datediff只代表间隔数

留意:此时不可能用 datediff 差值为七,因为,datediff只表示间隔数

本季度 select * from T_news where DATEPART(qq, addtime) =
DATEPART(qq, GETDATE()) and DATEPART(yy, addtime) = DATEPART(yy,
GETDATE())

select * from T_news where datediff(day,addtime,getdate())=0

一季度 select * from T_news where DATEPART(qq, addtime) =
DATEPART(qq, GETDATE()) and DATEPART(yy, addtime) = DATEPART(yy,
GETDATE())

当天:

当天 select \ from T_news where
datediff(day,addtime,getdate())=0*

select * from T_news where datediff(day,addtime,getdate())<= 2 and
datediff(day,addtime,getdate())>= 0

一月    select * from T_news WHERE (DATEPART(yy, addtime) =
DATEPART(yy, GETDATE())) AND (DATEPART(mm, addtime) = DATEPART(mm,
GETDATE()))