最近一个月,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()))

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

细心:此时无法用 datediff 差值为7,因为,datediff只代表间隔数

三天 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()))

一季度 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())=0*";

近期贰个月:

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

一月"SELECT * FROM T_news WHERE (DATEPART(yy, addtime) = DATEPART(yy, GETDATE())) AND (DATEPART(mm, addtime) = DATEPART(mm, GETDATE()))";

本文由必威发布于必威-数据,转载请注明出处:最近一个月,datediff只表示间隔数

TAG标签:
Ctrl+D 将本页面保存为书签,全面了解最新资讯,方便快捷。