- 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
MySQL query to convert a string into a month (Number)?
Use the str_to_date() method −
select month(str_to_date(yourColumnName,'%b')) from yourTableName;
Let us first create a table −
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, MonthName varchar(100) ); Query OK, 0 rows affected (0.76 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(MonthName) values('Jan'); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable(MonthName) values('Mar'); Query OK, 1 row affected (0.13 sec) Display all records from the table using select statement: mysql> select *from DemoTable;
Output
+----+-----------+ | Id | MonthName | +----+-----------+ | 1 | Jan | | 2 | Mar | +----+-----------+ 2 rows in set (0.00 sec)
Following is the query to convert a string into a month (Number) −
mysql> select month(str_to_date(MonthName,'%b')) from DemoTable;
Output
+------------------------------------+ | month(str_to_date(MonthName,'%b')) | +------------------------------------+ | 1 | | 3 | +------------------------------------+ 2 rows in set (0.05 sec)
- Related Articles
- MySQL query to convert timestamp to month?
- MySQL query to convert a string like “1h 15 min” into 75 minutes?
- How to convert a string into number in PHP?
- How to concatenate MySQL distinct query results into a string?
- C++ Program to convert the string into a floatingpoint number
- MySQL query to convert a single digit number to two-digit
- MongoDB query to convert numeric string to number
- MySQL query to convert YYYY-MM-DD to DD Month, YYYY date format
- MySQL query to select records from a table on the basis of a particular month number?
- MySQL query to select all entries from a particular month
- How to convert year, month, and day of the month into a complete date in R?
- Convert hex string to number in MySQL?
- Convert DateTime Value into String in MySQL?
- Golang Program to convert a number into a rational number
- C++ Program to convert a number into a complex number

Advertisements