- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Output only the name of the month instead of the month number in MySQL
To display only the month number, use DATE_FORMAT() along with STR_TO_DATE(). Let us first create a table:
mysql> create table DemoTable1320 -> ( -> MonthName varchar(20) -> ); Query OK, 0 rows affected (0.43 sec)
Example
Insert some records in the table using insert command −
mysql> insert into DemoTable1320 values('10/10/2010'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1320 values('11/12/2018'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1320 values('12/01/2019'); Query OK, 1 row affected (0.15 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable1320;
Output
+------------+ | MonthName | +------------+ | 10/10/2010 | | 11/12/2018 | | 12/01/2019 | +------------+ 3 rows in set (0.00 sec)
Example
Here is the query to outputting the name of the month instead of the number −
mysql> select date_format(str_to_date(MonthName,'%d/%m/%Y'),'%M') from DemoTable1320;
Output
+-----------------------------------------------------+ | date_format(str_to_date(MonthName,'%d/%m/%Y'),'%M') | +-----------------------------------------------------+ | October | | December | | January | +-----------------------------------------------------+ 3 rows in set (0.00 sec)
- Related Articles
- Getting month name instead of numeric month number in report in SAP
- Get Month Name from Month number in MySQL?
- Convert DATE timestamp to return only the month name in MySQL
- MySQL query to update only month in date?
- Want to fetch only the month part from a date in MySQL
- MySQL datatype to store month and year only?
- Convert datetime to get month name in MySQL?
- Display month by name and number in Java
- How to get the first day of the current month in MySQL?
- How to get the first day of the previous month in MySQL?
- The production of an article in a factory grows at a rate of 4 % per month. If the production in the month of June is 5408 articles, what were the number of articles produced in the month of April?
- Compare only day and month with date field in MySQL?
- How to convert number to month name in PHP?
- How to get the first day of next month in MySQL?
- How to get last day of the current month in MySQL?

Advertisements