Reputation: 304
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.
Upvotes: 0
Views: 19277
Reputation: 3
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
Upvotes: 0
Reputation: 1620
SELECT MONTHNAME(CONCAT(your_column)) as month from table_name;
Upvotes: 0
Reputation: 41
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.
Upvotes: 0
Reputation: 21
Use the following functions:
Month Number: MONTH()
Month Name: MONTHNAME()
You should use monthname()
function.
Upvotes: 2
Reputation: 263763
SELECT DATE_FORMAT('2013-12-01' + INTERVAL n MONTH, '%b') As Month_Name
change n
to the month number.
Upvotes: 0
Reputation: 3546
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
Upvotes: 0