Is there anyway to get the month short name from just the number of the month in mysql ? for example : if I give 3, I need to get Mar.
-
2http://stackoverflow.com/questions/7027129/mysql-monthname – Tarek Apr 30 '13 at 11:36
-
1MONTHNAME(STR_TO_DATE(3, '%m')), I used this but, it is giving month full name. But, I want short name – Banala Ramu Apr 30 '13 at 11:36
-
@banalaramu use then **substring()** with **str_to_date()**. – Vucko Apr 30 '13 at 11:37
8 Answers
Use the following functions:
Month Number: MONTH()
Month Name: MONTHNAME()
You should use monthname()
function.

- 21
- 1
There are a few options to retrieve this, date_format being one them, but it depends on how and what exactly you are trying to implement. I suggest you take a look at the MySQL Date documentation:
https://dev.mysql.com/doc/refman/4.1/en/date-and-time-functions.html

- 3,544
- 4
- 24
- 33
SELECT DATE_FORMAT('2013-12-01' + INTERVAL n MONTH, '%b') As Month_Name
change n
to the month number.

- 258,903
- 69
- 498
- 492
Hello this should answer your query
SELECT left(MONTHNAME(STR_TO_DATE(1, '%m')),3) from dual
dual
is used a spoof table when we dont want to refer a table in mysql but just want to execute the query.

- 10,519
- 8
- 40
- 45

- 31
- 6
SELECT MONTHNAME(CONCAT(your_column)) as month from table_name;

- 1,562
- 4
- 25
- 52
-
hey there. adding a link to documentation would be great! – Félix Adriyel Gagnon-Grenier Feb 28 '15 at 16:18
I know this question is aged, but found it relevant today.
Solution:
SELECT DATE_FORMAT(CONCAT(YEAR(NOW()),'-',LPAD( myMonthInteger ,2,'0'),'-01'),'%b')
Change the myMonthInteger
value to your column name or month index value (1-12). Returns NULL for other values.
Example using OP value of "3" for myMonthInteger:
SELECT DATE_FORMAT(CONCAT(YEAR(NOW()),'-',LPAD( 3,2,'0'),'-01'),'%b')
returns "Mar"
Explanation:
LPAD( myMonthInteger ,2,'0')
Adds a leading zero to the month integer if needed.
CONCAT(YEAR(NOW()),'-',LPAD( myMonthInteger ,2,'0'),'-01')
Creates a valid mysql date string with the current year and first day of month
DATE_FORMAT(CONCAT(YEAR(NOW()),'-',LPAD( myMonthInteger ,2,'0'),'-01'),'%b')
Formats the date string with '%b' type - short month name

- 3
- 3