mysql日期转换字符串
1、使用:DATE_FORMAT 将日期转换字符串,或者字符串转换日期
(1)将时间转换成字符串
将系统时间转换成字符串
MySQL> select date_format(now(), '%y%m%d %h:%i:%s');
+---------------------------------------+
| date_format(now(), '%y%m%d %h:%i:%s') |
+---------------------------------------+
| 160510 06:10:30 |
+---------------------------------------+
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)
网页名称:mysql日期转换字符串
标题链接:http://hbruida.cn/article/gipded.html
(1)将时间转换成字符串
将系统时间转换成字符串
MySQL> select date_format(now(), '%y%m%d %h:%i:%s');
+---------------------------------------+
| date_format(now(), '%y%m%d %h:%i:%s') |
+---------------------------------------+
| 160510 06:10:30 |
+---------------------------------------+
扩展: %Y:年 %c:月 %d:日 %H:小时 %i:分钟 %s:秒(2)将字符串转成日期
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)
网页名称:mysql日期转换字符串
标题链接:http://hbruida.cn/article/gipded.html