- 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
Convert VARCHAR data to MySQL date format?
To convert VARCHAR data to date format, you can use STR_TO_DATE() −
mysql> create table DemoTable1989 ( DueDate varchar(20) ); Query OK, 0 rows affected (0.91 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1989 values('31/01/2015'); Query OK, 1 row affected (0.52 sec) mysql> insert into DemoTable1989 values('01/12/2018'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable1989 values('25/10/2019'); Query OK, 1 row affected (0.11 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1989;
This will produce the following output −
+------------+ | DueDate | +------------+ | 31/01/2015 | | 01/12/2018 | | 25/10/2019 | +------------+ 3 rows in set (0.00 sec)
Here is the query to convert date data into MySQL date format:
mysql> select str_to_date(DueDate,'%d/%m/%Y') as MySQLDateFormat from DemoTable1989;
This will produce the following output −
+-----------------+ | MySQLDateFormat | +-----------------+ | 2015-01-31 | | 2018-12-01 | | 2019-10-25 | +-----------------+ 3 rows in set (0.05 sec)
- Related Articles
- Convert VARCHAR Date to a different format in MySQL?
- Convert varchar to date in MySQL?
- Convert string (varchar) to timestamp format in MySQL?
- Convert MySQL Unix-Timestamp format to date format?
- How to convert Python date format to 10-digit date format for mysql?
- How to convert a date format in MySQL?
- How to convert US date format to MySQL format in INSERT query?
- How to correctly convert a date format into a MySQL date?
- Format MySQL date and convert to year-month-day
- MySQL date format to convert dd.mm.yy to YYYY-MM-DD?
- How to select a specific record from MySQL if date is in VARCHAR format?
- Convert Date not in a proper format with MySQL?
- Set format specifier in MySQL STR_TO_DATE() and convert string to date
- Date format to convert dates like Jan 2017, May 2018 to complete date in MySQL
- Convert string (varchar) to double in MySQL

Advertisements