最近一个月

2019-10-19 22:59栏目:计算机论坛
TAG:

当天:

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(wk, addtime) = DATEPART(wk, GETDATE())) AND (DATEPART(yy, addtime) = DATEPART(yy, GETDATE()))

瞩目:此时不能够用 datediff 差值为7,因为,datediff只象征间隔数

本月:

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

最近贰个月:

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 DATEPART(qq, addtime) = DATEPART(qq, GETDATE()) and DATEPART(yy, addtime) = DATEPART(yy, GETDATE())

版权声明:本文由493333王中王开奖结果发布于计算机论坛,转载请注明出处:最近一个月