Name

TIME_FORMAT()

Synopsis

TIME_FORMAT(time, format_code)

This function returns the time value of the time element provided and formats it according to formatting codes given as the second argument. See Table 12-1 under the DATE_FORMAT() function earlier in this chapter for formatting codes, but only those related to time values. This function will return NULL or 0 for nontime formatting codes. Here is an example:

SELECT TIME_FORMAT(appointment, '%l:%i %p')
AS 'Appt. Time' FROM appointments
WHERE client_id = '8373'
AND appointment > SYSDATE( );

+------------+
| Appt. Time |
+------------+
|  1:00 PM   | 
+------------+

Get MySQL in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.