我正在尝试将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
提前致谢。
答案 0 :(得分:2)
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
的列表