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

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

王林
王林forward
2023-08-29 13:13:07492browse

如何使用 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)

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)

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete