TIME_FORMAT(time,format) : TIME_FORMAT « Date Time Functions « MySQL Tutorial






The TIME_FORMAT function can display a time in almost any format.

TIME_FORMAT() can only be passed time information, or it will return a NULL result.

TIME_FORMAT Output Formats

format ParameterOutput Format
%r12-hour time (hh:mm:ss (AM|PM))
%T24-hour time (hh:mm:ss)
%YNumeric year, 4 digits
%yNumeric year, 2 digits
%mMonth with leading 0 (01, 02-12)
%cMonth without leading 0 (1, 2-12)
%MMonth name (January, February, and so on)
%bMonth name, abbreviated (Jan, Feb, and so on)
%DDay of the month with an English suffix (1st, 2nd, and so on)
%dDay of the month with leading 0 (00, 01, 02-31)
%eDay of the month without leading 0 (0, 1, 2-31)
%WWeekday name (Sunday, Monday, and so on)
%aWeekday name, abbreviated (Sun, Mon, and so on)
%HHour (00, 01-23)
%kHour (0, 1-23)
%hHour (01, 02-12)
%IHour (01, 02-12)
%lHour (1, 2-12)
%iMinutes (00, 01-59)
%SSeconds (00, 01-59)
%sSeconds (00, 01-59)
%PAM or PM
%UWeek number in the year,in which Sunday is the first day of the week
$uWeek number in the year,in which Monday is the first day of the week
%X & %VYear and week number, respectively,in which Sunday is the first day of the week
%x & %vYear and week number, respectively,in which Monday is the first day of the week
%jDay of year with leading 0's (001, 002-366)
%wWeekday number (0=Sunday, 1=Monday, and so on)
%%Literal %


mysql>
mysql>
mysql> SELECT TIME_FORMAT(NOW(), '%H:%i:%s');
+--------------------------------+
| TIME_FORMAT(NOW(), '%H:%i:%s') |
+--------------------------------+
| 18:58:25                       |
+--------------------------------+
1 row in set (0.02 sec)

mysql>
mysql>








14.48.TIME_FORMAT
14.48.1.TIME_FORMAT(time,format)
14.48.2.TIME_FORMAT(time,format): The format string may contain format specifiers only for hours, minutes, and seconds