我正在尝试将MySQL字符串日期转换为Y-m-d H:i:s
格式。我目前正在使用此SQL,但它返回一个空值。我究竟做错了什么?
select
date_format(str_to_date(week_ending,'%l %d %F %Y'),'%Y-%m-%d %H:%i:%s') as week_ending
from worksheets
编辑
week_ending的格式如下: Friday 08 May 2015
提前致谢。
的正确格式str_to_date
应为
mysql> select str_to_date('Friday 08 May 2015','%W %d %M %Y');
+-------------------------------------------------+
| str_to_date('Friday 08 May 2015','%W %d %M %Y') |
+-------------------------------------------------+
| 2015-05-08 |
+-------------------------------------------------+
1 row in set (0.00 sec)
您使用的格式将返回null
mysql> select str_to_date('Friday 08 May 2015','%l %d %F %Y');
+-------------------------------------------------+
| str_to_date('Friday 08 May 2015','%l %d %F %Y') |
+-------------------------------------------------+
| NULL |
+-------------------------------------------------+
1 row in set, 1 warning (0.00 sec)
这是格式说明符https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-format的列表
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句