Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
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
<p>+------------+</p>| due_date | <p>+------------+</p>| 2020-04-30 | <p>| 2016-01-10 |</p>| 2018-03-21 | <p>+------------+</p>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
<p>+------------+</p>| ShowDate | <p>+------------+</p>| 30-04-2020 | <p>| 10-01-2016 |</p>| 21-03-2018 | <p>+------------+</p>3 rows in set (0.03 sec)
Advertisements
