- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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)
Advertisements