- 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
What MySQL returns if specified format string is not as per accordance with the date string passed as arguments to STR_TO_DATE() function?
If the specified format string and date string did not match then MySQL will return NULL value as output along with a warning. Following is an example to understand the same −
mysql> Select STR_TO_DATE('20172810', '%Y,%d%m'); +------------------------------------+ | STR_TO_DATE('20172810', '%Y,%d%m') | +------------------------------------+ | NULL | +------------------------------------+ 1 row in set, 1 warning (0.00 sec)
The query above returns NULL as output because the format string is having a comma (,) after %Y but date string is not having any comma after 2017.
mysql> Show Warnings\G *************************** 1. row *************************** Level: Warning Code: 1411 Message: Incorrect datetime value: '20172810' for function str_to_date 1 row in set (0.00 sec)
Similarly, on distinguishing the order of date units in format string from the date string, MySQL will perform same as above. An example is given below to understand it −
mysql> Select STR_TO_DATE('20172810', '%d%m%Y'); +-----------------------------------+ | STR_TO_DATE('20172810', '%d%m%Y') | +-----------------------------------+ | NULL | +-----------------------------------+ 1 row in set, 1 warning (0.00 sec)
In the above query, the order of units in the format string is changed from the order of units in the date string.
mysql> Show Warnings\G *************************** 1. row *************************** Level: Warning Code: 1411 Message: Incorrect datetime value: '20172810' for function str_to_date 1 row in set (0.00 sec)
Advertisements
To Continue Learning Please Login
Login with Google