(MSSQL) 이번 주 월요일, 다음 주 월요일 구하기

IT/Programming/MSSQL 2016. 1. 18. 12:30

 DECLARE @now datetime;
 DECLARE @next_week_monday_00 datetime
 DECLARE @this_week_monday_00 datetime

 SET @now = '2016-01-17'
 IF 1 = DATEPART(WEEKDAY, @now)
  SET @this_week_monday_00 = DATEADD(DAY, DATEDIFF(DAY, 0, DATEADD(DAY, -6, @now)), 0)
 ELSE
  SET @this_week_monday_00 = DATEADD(DAY, DATEDIFF(DAY, 0, DATEADD(DAY, DATEPART(WEEKDAY, @now) * -1 + 2, @now)), 0)
 SET @next_week_monday_00 = DATEADD(DAY, 7, @this_week_monday_00) 

 

설정

트랙백

댓글