SQLSERVER 查询本周一至周日数据

DECLARE @ThisWeekStartTime NVARCHAR(100),@ThisWeekEndTime NVARCHAR(100)--本周
SELECT @ThisWeekStartTime= CONVERT(nvarchar(10), DATEADD(wk, DATEDIFF(wk,0,DATEADD(dd, -1, getdate()) ), 0),121)--本周开始时间
SELECT @ThisWeekEndTime= CONVERT(nvarchar(10), DATEADD(wk, DATEDIFF(wk,0,DATEADD(dd, -1, getdate()) ), 6),121)--本周结束时间
select @ThisWeekStartTime [本周起始日],@ThisWeekEndTime [本周结束日]


--查询本周注册的新用户
select * from dbo.Accounts where RegisterDate>=DATEADD(wk, DATEDIFF(wk,0,DATEADD(dd, -1, getdate()) ), 0) 
and RegisterDate<DATEADD(wk, DATEDIFF(wk,0,DATEADD(dd, -1, getdate()) ), 7)
相关文章
相关标签/搜索