TIME_FORMAT
TIME_FORMAT(time, format)
Section titled “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
Section titled “Example”SELECT TIME_FORMAT('15:30:45', '%h:%i %p') AS `Formatted Time`;Output
Section titled “Output”| Formatted Time ||----------------|| 03:30 PM |Explanation
Section titled “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’.