Home > Database > Mysql Tutorial > body text

How to unload time/date values ​​in MySQL using TIME_FORMAT() function?

王林
Release: 2023-08-29 13:13:07
forward
495 people have browsed it

如何使用 TIME_FORMAT() 函数卸载 MySQL 中的时间/日期值?

The TIME_FORMAT() function is used in a similar way to the DATE_FORMAT() function, but it can only be used to unload time values. If the TIME_FORMAT() function is used to unload a date value, MySQL returns a NULL value.

For example, when we pass the time format unit as a parameter to the MySQL TIME_FORMAT() function, MySQL only unloads the time as shown below -

mysql> Select TIME_FORMAT("2017-10-22 13:03:45", "%h %i %s %p")AS 'OFFLOADED TIME';
+----------------+
| OFFLOADED TIME |
+----------------+
| 01 03 45 PM    |
+----------------+
1 row in set (0.00 sec)
Copy after login

However, when we pass the date format unit as When parameters are passed to the MySQL TIME_FORMAT() function, MySQL will return NULL as shown below -

mysql> Select TIME_FORMAT("2017-10-22 13:03:45", "%Y %M %D") AS 'OFFLOADED DATE';
+----------------+
| OFFLOADED DATE |
+----------------+
| NULL           |
+----------------+
1 row in set (0.00 sec)
Copy after login

The above is the detailed content of How to unload time/date values ​​in MySQL using TIME_FORMAT() function?. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template