sqlserver 获取上周周一 周五的日期

SET DATEFIRST 1
DECLARE @day1 DATETIME
DECLARE @dat5temp DATETIME
DECLARE @day5 VARCHAR(100)
SET @day1 = convert(char(10),dateadd(dd, - DATEPART (weekday , getdate())-6,getdate()),120)
SET @dat5temp = convert(char(10),dateadd(dd, - DATEPART (weekday , getdate())-2,getdate()),120)
SET @day5 = CAST(YEAR(@dat5temp) AS VARCHAR(4)) + '-' + CAST


--获取上周周一
select convert(char(10),dateadd(dd, - DATEPART (weekday , getdate()+@@DATEFIRST -1)-6,getdate()),120)
--获取上周周五
select convert(char(10),dateadd(dd, - DATEPART (weekday , getdate()+@@DATEFIRST -1)-2,getdate()),120)

两种方式是一样的

你可能感兴趣的:(oracle,Date,mysql,sqlserver)