我们可以在 DATE_FORMAT() 函数中同时使用这两个格式字符。下面的例子将阐明这一点 -
mysql> SELECT DATE_FORMAT(NOW(), 'The time is %a %h:%i:%s:%f %p');
+-----------------------------------------------------+
| DATE_FORMAT(NOW(), 'The time is %a %h:%i:%s:%f %p') |
+-----------------------------------------------------+
| The time is Sun 06:35:06:000000 AM |
+-----------------------------------------------------+
1 row in set (0.00 sec)
以上查询使用日期格式字符“%a”以及其他时间格式字符。
以下是同时使用这两种格式字符的另一个示例 -
mysql> SELECT DATE_FORMAT(NOW(), 'The date & time is %a %D %M %Y %h:%i:%s:%f %p');
+---------------------------------------------------------------------+
| DATE_FORMAT(NOW(), 'The date & time is %a %D %M %Y %h:%i:%s:%f %p') |
+---------------------------------------------------------------------+
| The date & time is Sun 29th October 2017 06:37:17:000000 AM |
+---------------------------------------------------------------------+
1 row in set (0.00 sec)