将 YYYY-MM-DD 转换为 DD 月份, YYYY 日期格式的 MySQL 查询
让我们首先创建一个表 -
mysql> create table DemoTable845(AdmissionDate date); Query OK, 0 rows affected (1.10 sec)
使用插入命令在表中插入一些记录 -
mysql> insert into DemoTable845 values('2018-01-21'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable845 values('2016-12-12'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable845 values('2019-08-05'); Query OK, 1 row affected (0.44 sec) mysql> insert into DemoTable845 values('2019-10-15'); Query OK, 1 row affected (0.19 sec)
使用 select 语句显示表中的所有记录 -
mysql> select *from DemoTable845;
这将产生以下输出 -
+---------------+ | AdmissionDate | +---------------+ | 2018-01-21 | | 2016-12-12 | | 2019-08-05 | | 2019-10-15 | +---------------+ 4 rows in set (0.00 sec)
以下是将 YYYY-MM-DD 转换为 DD 月份, YYYY 日期格式的查询 -
mysql> select date_format(AdmissionDate,'%e %M, %Y') from DemoTable845;
这将产生以下输出 -
+----------------------------------------+ | date_format(AdmissionDate,'%e %M, %Y') | +----------------------------------------+ | 21 January, 2018 | | 12 December, 2016 | | 5 August, 2019 | | 15 October, 2019 | +----------------------------------------+ 4 rows in set (0.00 sec)
广告