
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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)
- Related Questions & Answers
- What MySQL returns on passing an invalid string as an argument to STR_TO_DATE() function?
- What happens if the value of number ‘N’ in CONV() function is not as per accordance with its base?
- How to get string as date in MySQL with dates as dot format specifier?
- What MySQL returns if the search string is not in the list of strings provided as argument in FIELD() function?
- Which MySQL function returns a specified number of characters of a string as output?
- Replace date format with MySQL STR_TO_DATE
- What MySQL returns if we use NULL, as both the arguments, as one of the argument and as a separator, in CONCAT_WS() function?
- Set format specifier in MySQL STR_TO_DATE() and convert string to date
- What MySQL returns if we include time components along with date component as an argument to DATEDIFF() function?
- What MySQL returns if we include date components along with time component as an argument to TIMEDIFF() function?
- Format date with DATE_FORMAT() and STR_TO_DATE() in MySQL
- When MySQL SUBSTRING_INDEX() function returns the same string, provided in the argument, as output?
- What MySQL returns, if the length of the original string is greater than the length specified as an argument in LPAD() or RPAD() functions?
- Select timestamp as date string in MySQL?
- What MySQL COALESCE() function returns if it has a blank, but not NULL, as the first argument?
Advertisements