预计该年份将被选为当前年份而不是 00 年份,如下所示。
mysql> select str_to_date('Jul 15 12:12:51', '%b %e %T');
+--------------------------------------------+
| str_to_date('Jul 15 12:12:51', '%b %e %T') |
+--------------------------------------------+
| 0000-07-15 12:12:51 |
+--------------------------------------------+
预期结果:
| 2013-07-15 12:12:51 |
最佳答案
嗯,这是有意的。引用 doc :
Unspecified date or time parts have a value of 0, so incompletely specified values in str produce a result with some or all parts set to 0. [...] “Zero” dates or dates with part values of 0 are permitted unless the SQL mode is set to disallow such values.
很容易修复,顺便说一句:
select str_to_date(CONCAT(YEAR(NOW()), ' ', 'Jul 15 12:12:51'), '%Y %b %e %T');
-- July, 15 2013 12:12:51+0000
关于mysql - 在字符串中使用当前年份到日期函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17648828/