我需要计算为dd-MM-yyyy的字符串
从wwyy字符串(我需要一周的第一天或一周中的其他任何一天)
示例:现在我们在18的第42周,所以如果我输入4218 我会在15-10-2018或14-10-2018
BR, 伊丹
答案 0 :(得分:1)
declare @input char(4) set @input = 4218
SET DATEFIRST 1
declare @wk int set @wk = cast(SUBSTRING(@input,1,2) as int)
declare @yr int set @yr = 2000 + cast(SUBSTRING(@input,3,2) as int)
select dateadd (week, @wk, dateadd (year, @yr-1900, 0)) - 4 -
datepart(dw, dateadd (week, @wk, dateadd (year, @yr-1900, 0)) - 4) + 1
答案 1 :(得分:0)
与代码端分开,并在下面的查询中使用以实现您的结果。
DECLARE @WeekNo int= 42
DECLARE @Year int=2018
SELECT CAST(DATEADD(wk,@WeekNo-1,DATEADD(yy,@Year-1900,0)) AS DATE) AS first_day_of_week