Convert UK DATE to MySQL date?


The UK date format supports day-moth-year format. To convert it to MySQL date, use STR_TO_DATE(). Following is the syntax:

select str_to_date(yourColumnName,'%d/%m/%Y') from yourTableName;

Let us first create a table:

mysql> create table DemoTable728 (DueDate varchar(100));
Query OK, 0 rows affected (0.59 sec)

Insert some records in the table using insert command:

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)

Display all records from the table using select statement:

mysql> select *from DemoTable728;

This will produce the following output -

+------------+
| DueDate    |
+------------+
| 10/11/2019 |
| 31/01/2016 |
| 01/12/2015 |
| 11/03/2018 |
+------------+
4 rows in set (0.00 sec)

Following is the query to convert UK date format to MySQL date:

mysql> select str_to_date(DueDate,'%d/%m/%Y') from DemoTable728;

This will produce the following output -

+---------------------------------+
| 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)

Updated on: 22-Aug-2019

232 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements