当前位置:u赢电竞手机版 > uwin电竞app官网下载 > Sql Server中查询当天,最近三天,本周,本月,最

Sql Server中查询当天,最近三天,本周,本月,最

文章作者:uwin电竞app官网下载 上传时间:2019-09-04

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

注意:此时不能用 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(qq, addtime) = DATEPART(qq, GETDATE()) and DATEPART(yy, addtime) = DATEPART(yy, GETDATE())

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

本文由u赢电竞手机版发布于uwin电竞app官网下载,转载请注明出处:Sql Server中查询当天,最近三天,本周,本月,最

关键词: