totn MariaDB Functions

MariaDB: TIME_FORMAT Function

This MariaDB tutorial explains how to use the MariaDB TIME_FORMAT function with syntax and examples.

Description

The MariaDB TIME_FORMAT function formats a time as specified by a format mask.

Syntax

The syntax for the TIME_FORMAT function in MariaDB is:

TIME_FORMAT( time, format_mask )

Parameters or Arguments

time
The time to format.
format_mask

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)
%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)

Note

  • The TIME_FORMAT function only formats the hours, minutes, seconds, and microseconds found in a time value.
  • See also the DATE_FORMAT function.

Applies To

The TIME_FORMAT function can be used in the following versions of MariaDB:

  • MariaDB 10

Example

Let's look at some MariaDB TIME_FORMAT function examples and explore how to use the TIME_FORMAT function in MariaDB.

For example:

SELECT TIME_FORMAT('11:23:02', '%H %i %s');
Result: '11 23 02'

SELECT TIME_FORMAT('11:23:02', '%h:%i:%s %p');
Result: '11:23:02 AM'

SELECT TIME_FORMAT('11:23:02', '%h:%i%p');
Result: '11:23AM'

SELECT TIME_FORMAT('11:23:02.000001', '%r');
Result: '11:23:02 AM'

SELECT TIME_FORMAT('11:23:02.000001', '%T');
Result: '11:23:02'

SELECT TIME_FORMAT('01:23:02.000001', '%f');
Result: '000001'