0

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.

Banala Ramu
  • 304
  • 2
  • 3
  • 8

8 Answers8

5

Try this:

SELECT MONTHNAME(STR_TO_DATE(1, '%m'));//returns January

Also refer this

Linga
  • 10,379
  • 10
  • 52
  • 104
2

Use the following functions: Month Number: MONTH() Month Name: MONTHNAME() You should use monthname() function.

Max White
  • 21
  • 1
1

As per the manual, '%b' does just what you're after

Strawberry
  • 33,750
  • 13
  • 40
  • 57
0

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

Borniet
  • 3,544
  • 4
  • 24
  • 33
0
SELECT DATE_FORMAT('2013-12-01' + INTERVAL n MONTH, '%b') As Month_Name

change n to the month number.

John Woo
  • 258,903
  • 69
  • 498
  • 492
0

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.

user987339
  • 10,519
  • 8
  • 40
  • 45
jyotiska
  • 31
  • 6
0
SELECT MONTHNAME(CONCAT(your_column)) as month from table_name;
Praveen Srinivasan
  • 1,562
  • 4
  • 25
  • 52
0

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