Home  >  Article  >  Database  >  In MySQL, how to display time in other user-specified format?

In MySQL, how to display time in other user-specified format?

WBOY
WBOYforward
2023-08-27 22:25:03708browse

In MySQL, how to display time in other user-specified format?

We can also use the DATE_FORMAT() function to display time in other formats. In this case, the function will have two parameters, the first is the time and the second is the format string.

The following example will change the current time in the 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 the 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)

The above is the detailed content of In MySQL, how to display time in other user-specified format?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete
Previous article:Install MySQL on SolarisNext article:Install MySQL on Solaris