- 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
Format date to display month names with the entire date in MySQL?
For this, you can use DATE_FORMAT(). Let us first create a table −
mysql> create table DemoTable605 (DueDate date); Query OK, 0 rows affected (0.57 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable605 values('2019-01-21'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable605 values('2019-02-23'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable605 values(curdate()); Query OK, 1 row affected (0.15 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable605;
This will produce the following output −
+------------+ | DueDate | +------------+ | 2019-01-21 | | 2019-02-23 | | 2019-03-04 | | 2019-04-24 | | 2019-07-13 | +------------+ 5 rows in set (0.00 sec)
Following is the query to format date and display month names with the entire date in MySQL −
mysql> select DATE_FORMAT(DueDate, '%d.%M.%Y') from DemoTable605;
This will produce the following output −
+----------------------------------+ | DATE_FORMAT(DueDate, '%d.%M.%Y') | +----------------------------------+ | 21.January.2019 | | 23.February.2019 | | 04.March.2019 | | 24.April.2019 | | 13.July.2019 | +----------------------------------+ 5 rows in set (0.00 sec)
Advertisements