Bug #4094 STR_TO_DATE returns values for invalid dates
Submitted: 10 Jun 2004 19:35 Modified: 25 Aug 2004 18:37
Reporter: Ed Shelton Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:4.1.2 OS:Linux (Linux)
Assigned to: Paul DuBois CPU Architecture:Any

[10 Jun 2004 19:35] Ed Shelton
Description:

STR_TO_DATE will return non-NULL values for invalid dates.

Example:
SELECT STR_TO_DATE('02/30/2004','%m%d%Y');

Returns:
2004-02-30

This appears to happen for all dates, as long as month less than 13 and day is less than 32.

Note: The documentation says: "If str contains an illegal date, time, or datetime value, STR_TO_DATE() returns NULL"

Also, the documentation makes it appear that time would be returned with STR_TO_DATE, it is not returned.

How to repeat:
SELECT STR_TO_DATE('02/30/2004','%m%d%Y');
[11 Jun 2004 16:53] Dean Ellis
Regarding the returning of NULL, it currently returns NULL for illegal dates, which is subtly different than an invalid date (and is expected behavior for now) as you note.

For the rest, verifying that the function description does imply a time component will be returned whether or not the format string includes a time component (ie: "returns a DATETIME value", and the second example), but against 4.1.3 a time component is only returned if the format string includes a time component as well.

Either the function description needs to be updated or the function should match the description and return a DATETIME in all cases.

Thank you for the report.
[13 Jun 2004 18:57] Brian Aker
Paul, please update the documentation on this. Strict mode should return an error though.
[25 Aug 2004 18:37] Paul DuBois
Thank you for your bug report. This issue has been addressed in the
documentation. The updated documentation will appear on our website
shortly, and will be included in the next release of the relevant
product(s).

Additional info:

I updated the STR_TO_DATE() description with additional
information about return type, and a pointer to the section
that describes how dates are checked.