- 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
Converting a date in MySQL from string field?
To convert string to date in MySQL, you can use STR_TO_DATE() function. The syntax is as follows −
select str_to_date(‘StringValue’, '%d,%m,%Y') as anyVariableName;
Apply the above syntax in the following query wherein, we have a string value −
mysql> SELECT STR_TO_DATE('26,11,2018','%d,%m,%Y');
The following is the output −
+--------------------------------------+ | STR_TO_DATE('26,11,2018','%d,%m,%Y') | +--------------------------------------+ | 2018-11-26 | +--------------------------------------+ 1 row in set (0.00 sec)
Let us see another example, to change the format of the date −
SELECT STR_TO_DATE("November 26 2018", "%M %d %Y");
Sample Output
+---------------------------------------------+ | STR_TO_DATE("November 26 2018", "%M %d %Y") | +---------------------------------------------+ | 2018-11-26 | +---------------------------------------------+ 1 row in set (0.03 sec)
Advertisements
To Continue Learning Please Login
Login with Google