
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Get Month Name from Month number in MySQL?
You can use MONTHNAME() function from MySQL to display Month name from number. The syntax is as follows.
SELECT MONTHNAME(STR_TO_DATE(yourColumnName,’%m’)) as anyVariableName from yourTableName;
To understand the above concept, let us first create a table. The query to create a table is as follows.
mysql> create table MonthDemo -> ( -> MonthNum int -> ); Query OK, 0 rows affected (0.87 sec)
Insert some records in the table using insert command. The query is as follows −
mysql> insert into MonthDemo values(1); Query OK, 1 row affected (0.14 sec) mysql> insert into MonthDemo values(2); Query OK, 1 row affected (0.15 sec) mysql> insert into MonthDemo values(3); Query OK, 1 row affected (0.12 sec) mysql> insert into MonthDemo values(4); Query OK, 1 row affected (0.12 sec) mysql> insert into MonthDemo values(5); Query OK, 1 row affected (0.13 sec) mysql> insert into MonthDemo values(6); Query OK, 1 row affected (0.18 sec) mysql> insert into MonthDemo values(7); Query OK, 1 row affected (0.13 sec) mysql> insert into MonthDemo values(8); Query OK, 1 row affected (0.13 sec) mysql> insert into MonthDemo values(9); Query OK, 1 row affected (0.15 sec) mysql> insert into MonthDemo values(10); Query OK, 1 row affected (0.13 sec) mysql> insert into MonthDemo values(11); Query OK, 1 row affected (0.14 sec) mysql> insert into MonthDemo values(12); Query OK, 1 row affected (0.15 sec)
Display all records from the table using select command. The query is as follows.
mysql> select *from MonthDemo;
The following is the output.
+------------+ | MonthNum | +------------+ | 1 | | 2 | | 3 | | 4 | | 5 | | 6 | | 7 | | 8 | | 9 | | 10 | | 11 | | 12 | +------------+ 12 rows in set (0.00 sec)
Here is the query to display month name.
mysql> select monthname(str_to_date(MonthNum,'%m')) as MonthName from MonthDemo;
The following is the output.
+-----------+ | MonthName | +-----------+ | January | | February | | March | | April | | May | | June | | July | | August | | September | | October | | November | | December | +-----------+ 12 rows in set (0.00 sec)
- Related Articles
- Convert datetime to get month name in MySQL?
- Output only the name of the month instead of the month number in MySQL
- Getting month name instead of numeric month number in report in SAP
- Display month by name and number in Java
- How to convert number to month name in PHP?
- How to Convert Month Name to Number in Excel?
- Get Nth weekday of the month from a column with DATE records in MySQL
- Python Pandas - Get the month number of the period from the PeriodIndex object
- Create date from day, month, year fields in MySQL?
- Convert DATE timestamp to return only the month name in MySQL
- How to get the first day of next month in MySQL?
- How to get last day of the current month in MySQL?
- How to get last day of the previous month in MySQL?
- How to get last day of the next month in MySQL?
- How to get first day of every corresponding month in MySQL?

Advertisements