你的位置:首页 > 数据库

[数据库]Mysql小技巧总汇


1.datetime类型字段格式化

  • SELECT DATE_FORMAT(date,'%Y-%m-%d %h:%m:%s') date FROM message;

    结果:

+---------------------+
| date |
+---------------------+
| 2015-12-05 02:12:35 |
| 2015-12-05 02:12:55 |
| 2015-12-05 02:12:00 |
| 2015-12-05 02:12:20 |
| 2015-12-05 03:12:16 |
+---------------------+

    ('meaage' 表名,'date'一个datetim数据类型的字段)

    • 同上替换 DATE_FORMAT(date,'%Y-%m-%d')

      结果:

+------------+
| date |
+------------+
| 2015-12-05 |
| 2015-12-05 |
| 2015-12-05 |
| 2015-12-05 |
| 2015-12-05 |
+------------+