- 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
In MySQL, how can we display the date in other format specified by the user?
We need to use DATE_FORMAT() function to display the date in other formats. There would be two arguments of this function, first would be the date and second would be the format string.
Example − Suppose in the table ‘date_testing we have three dates in the following format
mysql> Select * from date_testing; +------------+ | Date | +------------+ | 2017-03-15 | | 2017-03-25 | | 2017-04-05 | +------------+ 3 rows in set (0.00 sec)
Now DATE_FORMAT() function will change the format of the above dates in the format given by the user as follows −
mysql> Select DATE_FORMAT(Date, '%W %D %M %Y')AS 'FORMATTED DATE' from date_testing; +---------------------------+ | FORMATTED DATE | +---------------------------+ | Wednesday 15th March 2017 | | Saturday 25th March 2017 | | Wednesday 5th April 2017 | +---------------------------+ 3 rows in set (0.00 sec)
Here in the above example %W, %D, etc. are date format characters.
Advertisements