
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Display Time in User-Specified Format in MySQL
We can also use DATE_FORMAT() function to display the time in other formats. In this case, there would be two arguments of this function, first would be the time and second would be the format string.
The following example will change the current time in specified format −
mysql> SELECT DATE_FORMAT(NOW(), 'The time is %h:%i:%s %p'); +-----------------------------------------------+ | DATE_FORMAT(NOW(), 'The time is %h:%i:%s %p') | +-----------------------------------------------+ | The time is 06:02:28 AM | +-----------------------------------------------+ 1 row in set (0.00 sec)
The following example will change the given time in specified format −
mysql> SELECT DATE_FORMAT('2017-10-29 06:03:25', 'The time is %h:%i:%s %p'); +---------------------------------------------------------------+ | DATE_FORMAT('2017-10-29 06:03:25', 'The time is %h:%i:%s %p') | +---------------------------------------------------------------+ | The time is 06:03:25 AM | +---------------------------------------------------------------+ 1 row in set (0.00 sec)
Advertisements