您可以使用DATE_FORMAT()将MySQL日期格式更改为特定格式。以下是语法-
select date_format(yourColumnName,yourFormatSpecifier) from yourTableName;
让我们首先创建一个表-
mysql> create table DemoTable ( ShippingDate date );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('2016-01-21'); mysql> insert into DemoTable values('2018-05-24'); mysql> insert into DemoTable values('2019-12-31');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+--------------+ | ShippingDate | +--------------+ | 2016-01-21 | | 2018-05-24 | | 2019-12-31 | +--------------+ 3 rows in set (0.00 sec)
以下是在MySQL查询中实现DATE_FORMAT()并设置日期格式的查询-
mysql> select date_format(ShippingDate,'%d/%m/%Y') from DemoTable;
这将产生以下输出-
+--------------------------------------+ | date_format(ShippingDate,'%d/%m/%Y') | +--------------------------------------+ | 21/01/2016 | | 24/05/2018 | | 31/12/2019 | +--------------------------------------+ 3 rows in set (0.00 sec)