This tutorial explains how to use the MySQL TIME_FORMAT function with syntax and examples.
The MySQL TIME_FORMAT function formats a time as specified by a format mask.
The syntax for the TIME_FORMAT function in MySQL is:
The time to format.
The format to apply to time. The following is a list of options for the format_mask parameter. These parameters can be used in many combinations.
Value | Description |
---|---|
%f | Microseconds (000000 to 999999) %f is available starting in MySQL 4.1.1 |
%H | Hour (00 to 23 generally, but can be higher) |
%h | Hour (00 to 12) |
%I | Hour (00 to 12) |
%i | Minutes (00 to 59) |
%p | AM or PM |
%r | Time in 12 hour AM or PM format (hh:mm:ss AM/PM) |
%S | Seconds (00 to 59) |
%s | Seconds (00 to 59) |
%T | Time in 24 hour format (hh:mm:ss) |
The TIME_FORMAT function can be used in the following versions of MySQL:
Let's look at some MySQL TIME_FORMAT function examples and explore how to use the TIME_FORMAT function in MySQL.
For example: