MySQL query to convert YYYY-MM-DD to DD Month, YYYY date format

MySQLMySQLi Database

Let us first create a table −

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

Insert some records in the table using insert command −

mysql> insert into DemoTable845 values('2018-01-21');
Query OK, 1 row affected (0.13 sec)
mysql> insert into DemoTable845 values('2016-12-12');
Query OK, 1 row affected (0.13 sec)
mysql> insert into DemoTable845 values('2019-08-05');
Query OK, 1 row affected (0.44 sec)
mysql> insert into DemoTable845 values('2019-10-15');
Query OK, 1 row affected (0.19 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable845;

This will produce the following output −

+---------------+
| AdmissionDate |
+---------------+
| 2018-01-21    |
| 2016-12-12    |
| 2019-08-05    |
| 2019-10-15    |
+---------------+
4 rows in set (0.00 sec)

Following is the query to convert YYYY-MM-DD to DD Month, YYYY date format −

mysql> select date_format(AdmissionDate,'%e %M, %Y') from DemoTable845;

This will produce the following output −

+----------------------------------------+
| date_format(AdmissionDate,'%e %M, %Y') |
+----------------------------------------+
| 21 January, 2018                       |
| 12 December, 2016                      |
| 5 August, 2019                         |
| 15 October, 2019                       |
+----------------------------------------+
4 rows in set (0.00 sec)
raja
Published on 03-Sep-2019 11:42:25
Advertisements