splitting a datetime column into year, month and week

前端 未结 3 1831
时光说笑
时光说笑 2021-01-12 07:24

I want to split a datetime column so that the year and the month both have their own column in a select statement output. I also want to have a column by week of the year, a

3条回答
  •  鱼传尺愫
    2021-01-12 08:25

    Here is another way. Use SQL Servers YEAR() and MONTH() functions. For week, I use datepart(week,Mydate) as noted by @DMK.

    SELECT YEAR(MyDate), MONTH(MyDate), DATEPART(WEEK,Mydate) From YourTable
    

提交回复
热议问题