How can I use TIME_FORMAT() function to offload time/date values in MySQL?

MySQLMySQLi Database

TIME_FORMAT() function can be used in a similar fashion as DATE_FORMAT() function but it can only be used for offloading time values. MySQL returns a NULL value if TIME_FORMAT() function is used for offloading date values.

For example, when we pass the time format units as arguments to MySQL TIME_FORMAT() function then MySQL offloaded only the time as follows −

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)

Whereas, when we pass the date format units as arguments to MySQL TIME_FORMAT() function then MySQL returns NULL as follows −

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)
raja
Published on 19-Feb-2018 16:06:03
Advertisements