让我们首先创建一个表-
mysql> create table DemoTable630 (ArrivalDate varchar(100));
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable630 values('2015-21-01'); mysql> insert into DemoTable630 values('2018-25-12'); mysql> insert into DemoTable630 values('2019-15-07'); mysql> insert into DemoTable630 values('2016-31-03');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable630;
这将产生以下输出-
+-------------+ | ArrivalDate | +-------------+ | 2015-21-01 | | 2018-25-12 | | 2019-15-07 | | 2016-31-03 | +-------------+ 4 rows in set (0.00 sec)
以下是转换日期格式的查询-
mysql> select str_to_date(ArrivalDate,'%Y-%d-%m') from DemoTable630;
这将产生以下输出-
+-------------------------------------+ | str_to_date(ArrivalDate,'%Y-%d-%m') | +-------------------------------------+ | 2015-01-21 | | 2018-12-25 | | 2019-07-15 | | 2016-03-31 | +-------------------------------------+ 4 rows in set (0.00 sec)