Skip to content
Fix Code Error

Convert Month Number to Month Name Function in SQL

March 13, 2021 by Code Error
Posted By: Saif Khan

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 am trying to avoid a CASE statement, if possible.

Solution

A little hacky but should work:

SELECT DATENAME(month, DATEADD(month, @mydate-1, CAST('2008-01-01' AS datetime)))
Answered By: Alexander Kojevnikov

Related Articles

  • add scroll bar to table body
  • Can't find why this datetime test fails, in F#
  • Obtain most recent value for based on index in a pandas…
  • Get week day name from a given month, day and year…
  • Difference in Months between two dates in JavaScript
  • How to add a unique id to an array in one loop instead of…
  • Converting between datetime, Timestamp and datetime64
  • Javascript add leading zeroes to date
  • Polymer nested dom-repeat templates are not updating when…
  • How to return only the Date from a SQL Server DateTime…

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

Docker: Copying files from Docker container to host

Next Post:

Getting the index of the returned max or min item using max()/min() on a list

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Get code errors & solutions at akashmittal.com
© 2022 Fix Code Error