1、使用:DATE_FORMAT 將日期轉(zhuǎn)換字符串,或者字符串轉(zhuǎn)換日期
(1)將時(shí)間轉(zhuǎn)換成字符串
將系統(tǒng)時(shí)間轉(zhuǎn)換成字符串
mysql> select date_format(now(), '%y%m%d %h:%i:%s');
+---------------------------------------+
| date_format(now(), '%y%m%d %h:%i:%s') |
+---------------------------------------+
| 160510 06:10:30 |
+---------------------------------------+
擴(kuò)展:
%Y:年
%c:月
%d:日
%H:小時(shí)
%i:分鐘
%s:秒
(2)將字符串轉(zhuǎn)成日期
partition_key字段信息為:160101
mysql> select date_format(partition_key,'%y-%m-%d') from t_order ;
+---------------------------------------+
| date_format(partition_key,'%y-%m-%d') |
+---------------------------------------+
| 16-01-01 |
| 16-01-01 |
| 16-01-01 |
| 16-01-01 |
| 16-01-01 |
| 16-01-01 |
| 16-01-01 |
| 16-01-01 |
| 16-01-01 |
| 16-01-01 |
| 16-01-01 |
| 16-01-01 |
| 16-01-01 |
| 16-01-01 |
+---------------------------------------+
14 rows in set (1.67 sec)