将英国日期转换为MySQL日期?
英国日期格式支持日 – 月 – 年格式。要将其转换为MySQL日期,请使用STR_TO_DATE()。以下是语法:
select str_to_date (yourColumnName,'%d /% m /%Y') from yourTableName;
让我们首先创建一个表:
mysql> create table DemoTable728 (DueDate varchar (100));
Query OK, 0 rows affected (0.59 sec)
使用插入命令在表中插入一些记录:
mysql> insert into DemoTable728 values('10/11/2019');
Query OK, 1 row affected (0.16 sec)
mysql> insert into DemoTable728 values('31/01/2016');
Query OK, 1 row affected (0.16 sec)
mysql> insert into DemoTable728 values('01/12/2015');
Query OK, 1 row affected (0.12 sec)
mysql> insert into DemoTable728 values('11/03/2018');
Query OK, 1 row affected (0.16 sec)
使用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)
以下是将英国日期格式转换为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)
阅读更多:MySQL 教程