Show date like 30-04-2020 instead of 2020-04-30 from MySQL database?


For this, use DATE_FORMAT() in MySQL. The syntax is as follows −

Example

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

Let us create a table −

Example

mysql> create table demo80
   -> (
   -> due_date date
   -> );
Query OK, 0 rows affected (0.74

Insert some records into the table with the help of insert command −

Example

mysql> insert into demo80 values('2020-04-30');
Query OK, 1 row affected (0.14

mysql> insert into demo80 values('2016-01-10');
Query OK, 1 row affected (0.17

mysql> insert into demo80 values('2018-03-21');
Query OK, 1 row affected (0.12

Display records from the table using select statement −

Example

mysql> select *from demo80;

This will produce the following output −

Output

+------------+

| due_date   |

+------------+

| 2020-04-30 |

| 2016-01-10 |

| 2018-03-21 |

+------------+

3 rows in set (0.00 sec)

Following is the query to show date like 30-04-2020 instead of 2020-04-30.

Example

mysql> select date_format(due_date,'%d-%m-%Y') as ShowDate from demo80;

This will produce the following output −

Output

+------------+

| ShowDate   |

+------------+

| 30-04-2020 |

| 10-01-2016 |

| 21-03-2018 |

+------------+

3 rows in set (0.03 sec)

Updated on: 11-Dec-2020

40 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements