SQL DATEPART(dw,date) need monday = 1 and sunday = 7

后端 未结 12 631
[愿得一人]
[愿得一人] 2020-12-23 16:27

I have a Query where I get the WeekDay of a date but by default:

  • Sunday = 1

  • Moday = 2

  • etc.

12条回答
  •  太阳男子
    2020-12-23 17:12

    I think this could work:

      select
        case when datepart(dw,[Date]) = 1 then 7 else DATEPART(DW,[Date])-1 end as WeekDay
    

提交回复
热议问题