Skip to content

Instantly share code, notes, and snippets.

@lefred
Created August 10, 2016 07:43
Show Gist options
  • Save lefred/1343bc190ba3de58c4e484fac4ff34b3 to your computer and use it in GitHub Desktop.
Save lefred/1343bc190ba3de58c4e484fac4ff34b3 to your computer and use it in GitHub Desktop.
STR_TO_DATE MySQL 5.7
mysql2 mysql> select str_to_date('9','%m');
+-----------------------+
| str_to_date('9','%m') |
+-----------------------+
| NULL |
+-----------------------+
1 row in set, 1 warning (0.00 sec)
mysql2 mysql> show variables like 'sql_mode'\G
*************************** 1. row ***************************
Variable_name: sql_mode
Value: ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
1 row in set (0.00 sec)
mysql2 mysql> set sql_mode='';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql2 mysql> select str_to_date('9','%m');
+-----------------------+
| str_to_date('9','%m') |
+-----------------------+
| 0000-09-00 |
+-----------------------+
1 row in set (0.00 sec)
Check the manual: http://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_str-to-date
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment