标签:sql
取本周周一与周末;
SELECT GETDATE() 当前时间,DATEADD(DAY,-CASE DATENAME(WEEKDAY,GETDATE()) WHEN ‘星期一‘ THEN 0 WHEN ‘星期二‘ THEN 1 WHEN ‘星期三‘ THEN 2 WHEN ‘星期四‘ THEN 3 WHEN ‘星期五‘ THEN 4 WHEN ‘星期六‘ THEN 5 ELSE 6 END,GETDATE()) 星期一日期,DATEADD(DAY,CASE DATENAME(WEEKDAY,GETDATE()) WHEN ‘星期一‘ THEN 6 WHEN ‘星期二‘ THEN 5 WHEN ‘星期三‘ THEN 4 WHEN ‘星期四‘
THEN 3 WHEN ‘星期五‘ THEN 2 WHEN ‘星期六‘ THEN 1 ELSE 0 END,GETDATE()) 星期日日期
取上周周一与周末:
SELECT CONVERT(nvarchar(10),DATEADD(wk, DATEDIFF(wk,0,DATEADD(dd, -8, ‘2017-08-06‘) ), 0),121)
SELECT CONVERT(nvarchar(10), DATEADD(wk, DATEDIFF(wk,0,DATEADD(dd, -8, ‘2017-08-02‘) ), 6),121)
本文出自 “技术经验分享” 博客,请务必保留此出处http://yataigp.blog.51cto.com/4779773/1953991
标签:sql
原文地址:http://yataigp.blog.51cto.com/4779773/1953991