Jump to: navigation, search

Mysql TIME FORMAT

From w3cyberlearnings

Contents

MySQL TIME_FORMAT Function

This function returns a time format for a give time.

Syntax TIME_FORMAT

  • expre: date or timestamp expression
  • format:
    • %f - Microseconds (000000..999999)
    • %H - Hour (00..23)
    • %h - Hour (01..12)
    • %I - Hour (01..12)
    • %i - Minutes, numeric (00..59)
    • %k - Hour (0..23)
    • %l - Hour (1..12)
    • %p - AM or PM
    • %r - Time, 12-hour (hh:mm:ss followed by AM or PM)
    • %S - Seconds (00..59)
    • %s - Seconds (00..59)
    • %T - Time, 24-hour (hh:mm:ss)
    • %% - A literal “%” character
    • %x - x, for any “x” not listed above
TIME_FORMAT();

Example 1

mysql> SELECT TIME_FORMAT('133:00:00', '%H %k %h %I %l');
+--------------------------------------------+
| TIME_FORMAT('133:00:00', '%H %k %h %I %l') |
+--------------------------------------------+
| 133 133 01 01 1                            |
+--------------------------------------------+
1 row in set (0.00 sec)

Example 2

mysql> SELECT TIME_FORMAT('23:42:33', '%H %i %s %p');
+----------------------------------------+
| TIME_FORMAT('23:42:33', '%H %i %s %p') |
+----------------------------------------+
| 23 42 33 PM                            |
+----------------------------------------+
1 row in set (0.00 sec)


Related Links



Navigation
Web
SQL
MISC
References