- 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
How to get string as date in MySQL with dates as dot format specifier?
To get string as date, use STR_TO_DATE() method. Let us first create a table −
mysql> create table DemoTable1445 -> ( -> AdmissionDate varchar(20) -> ); Query OK, 0 rows affected (0.46 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1445 values('01.10.2019'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable1445 values('31.12.2018'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable1445 values('01.02.2017'); Query OK, 1 row affected (0.11 sec)
Display all records from the table using select −
mysql> select * from DemoTable1445;
This will produce the following output −
+---------------+ | AdmissionDate | +---------------+ | 01.10.2019 | | 31.12.2018 | | 01.02.2017 | +---------------+ 3 rows in set (0.00 sec)
Following is the query to get string as date in MySQL −
mysql> update DemoTable1445 set AdmissionDate=str_to_date(AdmissionDate,'%.%.%'); Query OK, 3 rows affected (0.15 sec) Rows matched: 3 Changed: 3 Warnings: 0
Let us check the table records once again −
mysql> select * from DemoTable1445;
This will produce the following output −
+---------------+ | AdmissionDate | +---------------+ | 2019-10-01 | | 2018-12-31 | | 2017-02-01 | +---------------+ 3 rows in set (0.00 sec)
- Related Articles
- Set format specifier in MySQL STR_TO_DATE() and convert string to date
- What MySQL returns if specified format string is not as per accordance with the date string passed as arguments to STR_TO_DATE() function?
- Short Date ("d") Format Specifier
- How to format a string to date in as dd-MM-yyyy using java?
- Select timestamp as date string in MySQL?
- Long Date ("D") Format Specifier in C#
- Date format to convert dates like Jan 2017, May 2018 to complete date in MySQL
- How to format and display date in Java as '201904'
- How to change date format with DATE_FORMAT() in MySQL?
- Full Date Long Time ("F") Format Specifier in C#
- General Date Long Time ("G") Format Specifier in C#
- Full Date Short Time ("f") Format Specifier in C#
- C# General Date Short Time ("g") Format Specifier
- Get date format DD/MM/YYYY with MySQL Select Query?
- How to cast DATETIME as a DATE in MySQL?

Advertisements