那么问题在哪里呢?只能再次去官网找答案,找到#function_get-format
看到终极标准格式为:’%Y-%m-%d %H.%i.%s’,换成这个试试,看到范例中的差异在哪里了吗?就在于%H和%h的区别啊,如下所示:
mysql> select DATE_FORMAT(str_to_date('20150922 13:00:01', '%Y%m%d %h:%i:%s'),'%h:%i');
+--------------------------------------------------------------------------+
| DATE_FORMAT(str_to_date('20150922 13:00:01', '%Y%m%d %h:%i:%s'),'%h:%i') |
+--------------------------------------------------------------------------+
| NULL
|
+--------------------------------------------------------------------------+
1 row in set, 1 warning (0.00 sec)
mysql> select DATE_FORMAT(str_to_date('20150922 12:55:00', '%Y%m%d %h:%i:%s'),'%h:%i');
+--------------------------------------------------------------------------+
| DATE_FORMAT(str_to_date('20150922 12:55:00', '%Y%m%d %h:%i:%s'),'%h:%i') |
+--------------------------------------------------------------------------+
| 12:55
|
+--------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql>
然后标准的日期格式为:%Y%m%d %H:%i:%s’或者%Y-%m-%d %H:%i:%s’ 都可以的,如下所示:
select DATE_FORMAT(str_to_date(‘20150922 13:00:01’, ‘%Y%m%d %H:%i:%s’),’%H:%i’);
select DATE_FORMAT(str_to_date(‘20150922 12:55:00’, ‘%Y%m%d %H:%i:%s’),’%H:%i’);