- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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
How to update the date format in MySQL?
Let us first create a table −
mysql> create table DemoTable630 (ArrivalDate varchar(100)); Query OK, 0 rows affected (0.55 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable630 values('2015-21-01'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable630 values('2018-25-12'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable630 values('2019-15-07'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable630 values('2016-31-03'); Query OK, 1 row affected (0.17 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable630;
This will produce the following output −
+-------------+ | ArrivalDate | +-------------+ | 2015-21-01 | | 2018-25-12 | | 2019-15-07 | | 2016-31-03 | +-------------+ 4 rows in set (0.00 sec)
Following is the query to convert date format −
mysql> select str_to_date(ArrivalDate,'%Y-%d-%m') from DemoTable630;
This will produce the following output −
+-------------------------------------+ | str_to_date(ArrivalDate,'%Y-%d-%m') | +-------------------------------------+ | 2015-01-21 | | 2018-12-25 | | 2019-07-15 | | 2016-03-31 | +-------------------------------------+ 4 rows in set (0.00 sec)
Advertisements
To Continue Learning Please Login
Login with Google