Tutorialspoint

1 Answer
Anvi Jain

You can change the MySQL date format with a specific format using DATE_FORMAT(). Following is the syntax −

select date_format(yourColumnName,yourFormatSpecifier) from yourTableName;

Let us first create a table −

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

Insert some records in the table using insert command −

mysql> insert into DemoTable values('2016-01-21');
Query OK, 1 row affected (0.17 sec)

mysql> insert into DemoTable values('2018-05-24');
Query OK, 1 row affected (0.18 sec)

mysql> insert into DemoTable values('2019-12-31');
Query OK, 1 row affected (0.18 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable;

This will produce the following output −

+--------------+
| ShippingDate |
+--------------+
| 2016-01-21   |
| 2018-05-24   |
| 2019-12-31   |
+--------------+
3 rows in set (0.00 sec)

Following is the query to implement DATE_FORMAT() in MySQL query and set date format −

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

This will produce the following output −

+--------------------------------------+
| date_format(ShippingDate,'%d/%m/%Y') |
+--------------------------------------+
| 21/01/2016                           |
| 24/05/2018                           |
| 31/12/2019                           |
+--------------------------------------+
3 rows in set (0.00 sec)

Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.