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.
33 Answers
I think this is the best way to get the month name when you have the month number
Select DateName( month , DateAdd( month , @MonthNumber , 0 ) - 1 )
Or
Select DateName( month , DateAdd( month , @MonthNumber , -1 ) )

- 178,213
- 47
- 333
- 501

- 7,860
- 8
- 36
- 48
-
25for readability purposes I would actually write it like this: Select DateName( month , DateAdd( month , @MonthNumber - 1 , '1900-01-01' ) ) – Valentino Vranken Jun 29 '10 at 06:50
-
11one possible alternative solution Select DateName( month , DateAdd( month , @MonthNumber , -1 )) – Asif Aug 13 '13 at 09:40
-
5That's perfect. This should be the answer. – gotqn Oct 08 '13 at 13:35
-
The simpler the better! – mrddr Apr 21 '21 at 11:26
A little hacky but should work:
SELECT DATENAME(month, DATEADD(month, @mydate-1, CAST('2008-01-01' AS datetime)))

- 17,580
- 5
- 49
- 46
-
2Why the '-1'? Is that needed because the months in SQL Server are offset by one? – DoomerDGR8 Nov 01 '16 at 08:40
-
2@DoomerDGR8 it's actually because the date that's being used to seed the dateadd function starts at 1. if we need January's datename, we would be adding 1 month to 2008-01-01, which would give us 2008-02-01, which is February. so we subtract 1 to account for this, and we get January again. – DForck42 Dec 05 '16 at 16:11
-
To get around the problem of subtracting 1 from your datetime, use a datetime in December as opposed to January. For example SELECT DATENAME(month, DATEADD(month, @mydate, CAST('1978-12-01' AS datetime))) – Steve Matthews Sep 01 '17 at 13:26
-
6This is a good piece of information, but fails to actually answer the question of how to convert a month number to a month name (Rather answers how to get a month name from a date). You've assumed that he has the datetime value rather than just the month number; to get this to work you now need to 'invent' a date/time value. Think the solution from leoinfo was a bit more relevant – schizoid04 Jun 04 '18 at 19:51
SUBSTRING('JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC ', (@intMonth * 4) - 3, 3)

- 12,296
- 5
- 48
- 66

- 851
- 6
- 2
-
12I like this very left-field alternative way of thinkng! Food for thought – Michael Rodrigues Feb 22 '12 at 04:28
-
4And it's deterministic! Can be used as computed column too, thanks! – Irawan Soetomo Jul 13 '12 at 07:37
-
1nice... i was looking for some simple code to get months from jan to [#] and this worked great. for displaying several months, just change to something like this>> SUBSTRING('JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC ',0, (@intMonth * 4)) – Pablo Contreras Mar 26 '15 at 17:46
-
2I definitely wouldn't think of this as the "right way," but it's a fun way that could be used to solve other problems. – Paul Mar 23 '18 at 14:18
It is very simple.
select DATENAME(month, getdate())
output : January

- 727
- 2
- 10
- 25
-
6
-
3This is not an answer to the question. He is asking how to implement a function like MonthName(1). – amuliar Mar 30 '18 at 08:08
-
How is GETDATE() an integer representing a month? Why is this being upvoted? – TamusJRoyce Dec 30 '22 at 05:15
Starting with SQL Server 2012, you can use FORMAT and DATEFROMPARTS to solve this problem. (If you want month names from other cultures, change: en-US
)
select FORMAT(DATEFROMPARTS(1900, @month_num, 1), 'MMMM', 'en-US')
If you want a three-letter month:
select FORMAT(DATEFROMPARTS(1900, @month_num, 1), 'MMM', 'en-US')
If you really want to, you can create a function for this:
CREATE FUNCTION fn_month_num_to_name
(
@month_num tinyint
)
RETURNS varchar(20)
AS
BEGIN
RETURN FORMAT(DATEFROMPARTS(1900, @month_num, 1), 'MMMM', 'en-US')
END

- 3,634
- 1
- 18
- 23
-
1
-
It's probably not the most efficient, but it's probably the most easily readable. – Paul Jan 08 '19 at 23:01
-
1
-
@RosdiKasim I've been bit too many times by hard-coded manual date formatting with different localizations. – Paul Jan 28 '22 at 17:24
You can use the inbuilt CONVERT
function
select CONVERT(varchar(3), Date, 100) as Month from MyTable.
This will display first 3 characters of month (JAN,FEB etc..)

- 12,296
- 5
- 48
- 66
in addition to original
SELECT DATENAME(m, str(2) + '/1/2011')
you can do this
SELECT DATENAME(m, str([column_name]) + '/1/2011')
this way you get names for all rows in a table. where [column_name] represents a integer column containing numeric value 1 through 12
2 represents any integer, by contact string i created a date where i can extract the month. '/1/2011' can be any date
if you want to do this with variable
DECLARE @integer int;
SET @integer = 6;
SELECT DATENAME(m, str(@integer) + '/1/2011')
In some locales like Hebrew, there are leap months dependant upon the year so to avoid errors in such locales you might consider the following solution:
SELECT DATENAME(month, STR(YEAR(GETDATE()), 4) + REPLACE(STR(@month, 2), ' ', '0') + '01')

- 4,399
- 1
- 24
- 27
-
1Is there a function to convert a date to a Jewish date in SQL? Not that I know of... – Hila DG Oct 20 '16 at 03:45
-
function to convert to Jewish date: http://blogs.microsoft.co.il/gerireshef/2011/03/29/%D7%94%D7%9C%D7%95%D7%97-%D7%94%D7%A2%D7%91%D7%A8%D7%99-%D7%91%D7%A2%D7%96%D7%A8%D7%AA-tsql/ – AJ AJ Oct 23 '18 at 10:08
Use this statement to convert Month numeric value to Month name.
SELECT CONVERT(CHAR(3), DATENAME(MONTH, GETDATE()))

- 275
- 3
- 5
-
-
How is GETDATE() an integer representing a month? Why is this being upvoted? – TamusJRoyce Dec 30 '22 at 05:19
Just subtract the current month from today's date, then add back your month number. Then use the datename function to give the full name all in 1 line.
print datename(month,dateadd(month,-month(getdate()) + 9,getdate()))

- 186
- 1
- 6
-
-
1Yes, 9 represents the desired month as an integer. If you use the integer "4", the line of code returns "April". – Geoffrey Fuller Feb 04 '23 at 01:59
To convert month number to month name, try the below
declare @month smallint = 1
select DateName(mm,DATEADD(mm,@month - 1,0))

- 3,465
- 2
- 20
- 27
i think this is enough to get month name when u have date.
SELECT DATENAME(month ,GETDATE())

- 50,732
- 33
- 89
- 96

- 63
- 1
You can use the convert functin as below
CONVERT(VARCHAR(3), DATENAME(MM, GETDATE()), 100)
Declare @MonthNumber int
SET @MonthNumber=DatePart(Month,GETDATE())
Select DateName( month , DateAdd( month , @MonthNumber , 0 ) - 1 )
Explaination:
- First Decalre Variable
MonthNumber
- Get Current Month for
DatePart
which Return Month Number - Third Query Return Month Name

- 8,320
- 6
- 44
- 52

- 11
- 1
Working for me
SELECT MONTHNAME(<fieldname>) AS "Month Name" FROM <tablename> WHERE <condition>

- 51,061
- 28
- 99
- 211

- 19
- 1
-
syntax error. plus
cannot be a date or datetime. It must be an integer. Which would result in Jan – TamusJRoyce Dec 30 '22 at 05:20
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 |

- 4,769
- 5
- 29
- 34
-
You can find documentation in here. https://www.w3resource.com/mysql/date-and-time-functions/mysql-monthname-function.php – Janaka Pushpakumara Apr 13 '18 at 09:09
-
You can create a function like this to generate the Month and do SELECT dbo.fn_GetMonthFromDate(date_column) as Month FROM table_name
/****** Object: UserDefinedFunction [dbo].[fn_GetMonthFromDate] Script Date: 11/16/2018 10:26:33 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[fn_GetMonthFromDate]
(@date datetime)
RETURNS varchar(50)
AS
BEGIN
DECLARE @monthPart int
SET @monthPart = MONTH(@date)
IF @monthPart = 1
BEGIN
RETURN 'January'
END
ELSE IF @monthPart = 2
BEGIN
RETURN 'February'
END
ELSE IF @monthPart = 3
BEGIN
RETURN 'March'
END
ELSE IF @monthPart = 4
BEGIN
RETURN 'April'
END
ELSE IF @monthPart = 5
BEGIN
RETURN 'May'
END
ELSE IF @monthPart = 6
BEGIN
RETURN 'June'
END
ELSE IF @monthPart = 7
BEGIN
RETURN 'July'
END
ELSE IF @monthPart = 8
BEGIN
RETURN 'August'
END
ELSE IF @monthPart = 9
BEGIN
RETURN 'September'
END
ELSE IF @monthPart = 10
BEGIN
RETURN 'October'
END
ELSE IF @monthPart = 11
BEGIN
RETURN 'November'
END
ELSE IF @monthPart = 12
BEGIN
RETURN 'December'
END
RETURN NULL END

- 76
- 9
-
1Would use a case statement. But at least this is using month as an integer – TamusJRoyce Dec 30 '22 at 05:14
This one worked for me:
@MetricMonthNumber (some number)
SELECT
(DateName( month , DateAdd( month , @MetricMonthNumber - 1 , '1900-01-01' ) )) AS MetricMonthName
FROM TableName
From a post above from @leoinfo and @Valentino Vranken. Just did a quick select and it works.

- 21,844
- 12
- 67
- 78

- 11
- 1
Here is my solution using some information from others to solve a problem.
datename(month,dateadd(month,datepart(month,Help_HelpMain.Ticket_Closed_Date),-1)) as monthname

- 1
- 1
There is no system defined function in SQL server. But you can create your own user-defined function- a scalar function. You would find scalar functions in the Object Explorer for your database: Programmability->Functions->Scalar-valued Functions. Below, I use a table variable to bring it all together.
--Create the user-defined function
CREATE FUNCTION getmonth (@num int)
RETURNS varchar(9) --since 'September' is the longest string, length 9
AS
BEGIN
DECLARE @intMonth Table (num int PRIMARY KEY IDENTITY(1,1), month varchar(9))
INSERT INTO @intMonth VALUES ('January'), ('February'), ('March'), ('April'), ('May')
, ('June'), ('July'), ('August') ,('September'), ('October')
, ('November'), ('December')
RETURN (SELECT I.month
FROM @intMonth I
WHERE I.num = @num)
END
GO
--Use the function for various months
SELECT dbo.getmonth(4) AS [Month]
SELECT dbo.getmonth(5) AS [Month]
SELECT dbo.getmonth(6) AS [Month]
This is what I use:
SELECT TRIM(SUBSTRING('January February March April May June July August SeptemberOctober November December ', @MonthNumber * 9 - 8,9))

- 1,850
- 1
- 15
- 14
to_char(to_date(V_MONTH_NUM,'MM'),'MONTH')
where V_MONTH_NUM
is the month number
SELECT to_char(to_date(V_MONTH_NUM,'MM'),'MONTH') from dual;

- 30,033
- 48
- 152
- 225

- 9
-
This looks like it's referring to Oracle. The post is tagged with SQL 2005. – Philter Jun 03 '13 at 14:47
Use this statement for getting month name:
DECLARE @date datetime
SET @date='2015/1/4 00:00:00'
SELECT CAST(DATENAME(month,@date ) AS CHAR(3))AS 'Month Name'
This will give you short month name. Like this: Jan, Feb, Mar, etc.

- 529
- 1
- 12
- 25
Try this: SELECT MONTHNAME(concat('1970-',[Month int val],'-01'))
For example- SELECT MONTHNAME(concat('1970-',4,'-01'))
The answer is - April

- 5,690
- 6
- 40
- 58

- 145
- 2
- 11
If anyone is trying to get the same kind of thing in MySQL. please check below query.
SELECT MONTH(STR_TO_DATE('November', '%M'))
By this I got required result.

- 139
- 5
Use this statement
SELECT TO_CHAR(current_date,'dd MONTH yyyy') FROM dual
this will convert the month number to month full string
-
5TO_CHAR() is an Oracle function. The OP is using SQL Server, which has the different but equivalent CONVERT function. – APC Sep 28 '11 at 16:04