Change date format in MySQL database table to d/m/y


Following is the syntax −

select date_format(yourColumnName,'%d/%m/%Y') as anyAliasName from yourTableName;

Let us first create a table −

mysql> create table DemoTable
(
   AdmissionDate date
);
Query OK, 0 rows affected (0.89 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable values('2019-01-21');
Query OK, 1 row affected (0.17 sec)
mysql> insert into DemoTable values('2019-09-09');
Query OK, 1 row affected (0.13 sec)
mysql> insert into DemoTable values('2018-12-31');
Query OK, 1 row affected (0.19 sec)
mysql> insert into DemoTable values('2017-11-01');
Query OK, 1 row affected (0.16 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable;

This will produce the following output −

+---------------+
| AdmissionDate |
+---------------+
|    2019-01-21 |
|    2019-09-09 |
|    2018-12-31 |
|    2017-11-01 |
+---------------+
4 rows in set (0.00 sec)

Following is the query to change date format to d/m/y format −

mysql> select date_format(AdmissionDate,'%d/%m/%Y') as AdmissionDate from DemoTable;

This will produce the following output −

+---------------+
| AdmissionDate |
+---------------+
| 21/01/2019    |
| 09/09/2019    |
| 31/12/2018    |
| 01/11/2017    |
+---------------+
4 rows in set (0.00 sec)

Updated on: 07-Oct-2019

273 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements