TIME_FORMAT
TIME_FORMAT function in SQL is used to format the time values according to specified format. It returns the formatted version of a TIME or DATETIME value as a string in a specific format.
TIME_FORMAT(time, format)
- time: The time string to be formatted. This can be in various time formats and is interpreted by the function to be rendered in the specified format.
- format: A string pattern that defines the desired format for the time string. It’s represented with format specifiers which are percent-prefixed directives that tell the function how to display the time value. For example, ‘%H
Example
Output
Explanation
The TIME_FORMAT()
function in SQL is a date function that is used to format a time as specified by a format string. It accepts two arguments - the time value and the format string. In our example, ‘15:30:45’ is the time value and ‘%h:%i %p’ is the format string. The function returns the formatted time as ‘03:30 PM’.