SQLServer查询近日一天,四日,16日,5月,一季度

作者:数据库

当天:

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

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()))*

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

留心:此时不可能用 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(wk, addtime) = DATEPART(wk, GETDATE())) AND (DATEPART(yy, addtime) = DATEPART(yy, GETDATE()))

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

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

本文由ca88发布,转载请注明来源

关键词: ca88网址 ac88亚洲城 Sql Server C#编程