将UK DATE转换为MySQL日期?
英国日期格式支持日月年格式。要将其转换为MySQL日期,请使用STR_TO_DATE()。以下是语法:
select str_to_date(yourColumnName,'%d/%m/%Y') from yourTableName;
让我们首先创建一个表:
mysql> create table DemoTable728 (DueDate varchar(100));
使用insert命令在表中插入一些记录:
mysql> insert into DemoTable728 values('10/11/2019'); mysql> insert into DemoTable728 values('31/01/2016'); mysql> insert into DemoTable728 values('01/12/2015'); mysql> insert into DemoTable728 values('11/03/2018');
使用select语句显示表中的所有记录:
mysql> select *from DemoTable728;
这将产生以下输出-
+------------+ | DueDate | +------------+ | 10/11/2019 | | 31/01/2016 | | 01/12/2015 | | 11/03/2018 | +------------+ 4 rows in set (0.00 sec)
以下是将UK日期格式转换为MySQL日期的查询:
mysql> select str_to_date(DueDate,'%d/%m/%Y') from DemoTable728;
这将产生以下输出-
+---------------------------------+ | str_to_date(DueDate,'%d/%m/%Y') | +---------------------------------+ | 2019-11-10 | | 2016-01-31 | | 2015-12-01 | | 2018-03-11 | +---------------------------------+ 4 rows in set (0.00 sec)