Wednesday, December 29, 2010

Convert month number to month name in sql

In this blog I will explain you how to convert month number to month name in sql. To explain it I have used

SELECT DATENAME( MONTH , DATEADD( MONTH , @MONTHNUMBER , 0 ) - 1 ).Below is the code snippet:


DECLARE @MONTHNUMBER INT

SET @MONTHNUMBER=1

SELECT DATENAME( MONTH , DATEADD( MONTH , @MONTHNUMBER , 0 ) - 1 ) AS [MONTHNAME]

-OUTPUT


MONTHNAME

------------------------------

January

DECLARE @MONTHNUMBER INT


SET @MONTHNUMBER=12

SELECT DATENAME( MONTH , DATEADD( MONTH , @MONTHNUMBER , 0 ) - 1 ) AS [MONTHNAME]

--OUTPUT


MONTHNAME

------------------------------

December



2 ).Below is the code snippet:

SELECT CONVERT(VARCHAR(3), DATENAME(MM, CreatedDate_ColumnName), 100)

No comments:

Post a Comment