以下是语法-select date_format(yourColumnName,'%d/%m/%Y') as anyAliasName from yourTableName;
让我们首先创建一个表-mysql> create table DemoTable
(
AdmissionDate date
);
使用插入命令在表中插入一些记录-mysql> insert into DemoTable values('2019-01-21');
mysql> insert into DemoTable values('2019-09-09');
mysql> insert into DemoTable values('2018-12-31');
mysql> insert into DemoTable values('2017-11-01');
使用select语句显示表中的所有记录-mysql> select *from DemoTable;
这将产生以下输出-+---------------+
| AdmissionDate |
+---------------+
| 2019-01-21 |
| 2019-09-09 |
| 2018-12-31 |
| 2017-11-01 |
+---------------+
4 rows in set (0.00 sec)
以下是将日期格式更改为d / m / y格式的查询-mysql> select date_format(AdmissionDate,'%d/%m/%Y') as AdmissionDate from DemoTable;
这将产生以下输出-+---------------+
| AdmissionDate |
+---------------+
| 21/01/2019 |
| 09/09/2019 |
| 31/12/2018 |
| 01/11/2017 |
+---------------+
4 rows in set (0.00 sec)