Convert month name to month number in SQL Server

后端 未结 13 1374
情话喂你
情话喂你 2020-12-01 13:57

In T-SQL what is the best way to convert a month name into a number?

E.g:

\'January\' -> 1
\'February\' -> 2
\'March\' -> 3
13条回答
  •  没有蜡笔的小新
    2020-12-01 14:50

    How about this?

    select DATEPART(MM,'january 01 2011') -- returns 1
    select DATEPART(MM,'march 01 2011')  -- returns 3
    select DATEPART(MM,'august 01 2011') -- returns 8
    

提交回复
热议问题