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

WBOY
Release: 2023-08-27 22:25:03
forward
619 people have browsed it

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)
Copy after login

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!