
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
In MySQL, how can we display time in other format specified by the user?
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)
- Related Articles
- In MySQL, how can we display the date in other format specified by the user?
- How can we change MySQL user password by using the ALTER USER statement?
- How can we create a MySQL user account by omitting the hostname?
- How can we change MySQL user password by using UPDATE statement?
- How can we create a MySQL one-time event that executes after some specified time interval?
- How can we change MySQL user password by using the SET PASSWORD statement?
- How can we create user accounts in MySQL database server?
- How can we create a MySQL recurring event that executes after a specified time period and ends after a specified time period?
- How can we retrieve the length of a specified string in MySQL?
- How can we offload the time/date handling in MySQL?
- How can we retrieve the output having decimal values of a column in a specified format?
- How can we insert current date and time automatically on inserting values in other columns in MySQL?
- In MySQL, how can we use FROM_UNIXTIME() function with format string?
- How can we grant privileges to a MySQL user?
- How can we revoke privileges from a MySQL user?

Advertisements