TIME_FORMAT( )

This MySQL function returns the time value of the time element provided and formats it according to formatting codes given.

Syntax

Below is the syntax for this command. Text within square brackets (i.e, [ and ] ) are optional. Choices are separated by bars (i.e, | ). Ellipses preceded by a comma indicates a repeating pattern. Ellipses before or after syntax are used to highlight a relevant except from the larger syntax. Text displayed in italic letters represent text that should be replaced with the specific names related to the database (e.g., column with the name of the column).

TIME_FORMAT(time, format_code)

Explanation

This function returns the time value of the time element provided and formats it according to formatting codes given as the second argument. See the table under DATE_FORMAT( ) for formatting codes, but only those related to time values. This function will return NULL or 0 for non-time formatting codes.

Examples

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

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