当前位置: 奥门金沙手机娱乐网址 > 数据库 > 正文

最近一个月

时间:2019-10-04 14:48来源:数据库
--当天: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,
--当天:

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

 

编辑:数据库 本文来源:最近一个月

关键词:

  • 上一篇:没有了
  • 下一篇:没有了