Convert Month Number to Month Name Function in SQL

前端 未结 30 2063
予麋鹿
予麋鹿 2020-11-22 11:53

I have months stored in SQL Server as 1,2,3,4,...12. I would like to display them as January,February etc. Is there a function in SQL Server like MonthName(1) = January? I a

30条回答
  •  孤城傲影
    2020-11-22 12:36

    you can get the date like this. eg:- Users table

    id name created_at
    1  abc  2017-09-16
    2  xyz  2017-06-10
    

    you can get the monthname like this

    select year(created_at), monthname(created_at) from users;
    

    output

    +-----------+-------------------------------+
    | year(created_at) | monthname(created_at)  |
    +-----------+-------------------------------+
    |      2017        | september              |
    |      2017        | june                   |
    

提交回复
热议问题