SQL Convert Week Number to Date (dd/MM)

后端 未结 4 2022
一向
一向 2020-12-07 02:05

I am trying to convert the week number (for example: 21) in SQL-Server to the date (from the Monday of that week) in dd/MM format.

4条回答
  •  半阙折子戏
    2020-12-07 02:53

    This will do:

    DECLARE @y int = 2016,
            @w int = 21
    
    SELECT CONVERT(nvarchar(5),DATEADD(day,@w*7-(DATEPART(WEEKDAY,CAST(@y as nvarchar(4))+'-01-01')-2),CAST(@y as nvarchar(4))+'-01-01'),3)
    

    Output:

    23/05
    

提交回复
热议问题