All Products
Search
Document Center

MaxCompute:FORMAT_TIME

Last Updated:Mar 26, 2026

FORMAT_TIME formats a BIGINT time value, expressed in microseconds, into a STRING using a specified format string.

Syntax

STRING FORMAT_TIME(BIGINT <time>, STRING <format>)

Quick example

-- Returns 13:24:33.000.
SELECT FORMAT_TIME(48273000000, '%H:%M:%S.ff3');

Parameters

time

Type: BIGINT. Required.

A time value in microseconds. Use the TO_TIME function to construct this value from a time string.

In the MaxCompute V1.0 data type version, if this parameter is a STRING or DOUBLE, it undergoes implicit conversion to BIGINT before the function runs.

format

Type: STRING. Required.

A format string that controls the output. Supported specifiers:

Specifier Aliases Description Example output
%H HH, hh Hour 13
%M MI, mi Minute 24
%S SS, ss Second 33
ff3 Milliseconds (3-digit fractional seconds) 000
%E<n>S Fractional seconds with <n> digits of precision %E3S00.123
%E*S Fractional seconds with full 6-digit precision 00.123456

Aliases: For each time component, the Specifier column shows the canonical form. The aliases in the Aliases column produce identical output.

Sub-second precision: The three fractional-second specifiers all control precision below the second boundary. They differ only in how the digit count is specified:

  • ff3 always outputs exactly 3 digits (milliseconds).

  • %E<n>S outputs <n> digits, where <n> is a literal integer in the format string (for example, %E6S for microseconds).

  • %E*S outputs the full 6-digit precision.

Non-specifier text in the format string is passed through as-is, so you can embed specifiers inside a sentence.

Return value

Returns a STRING. If either time or format is NULL, the function returns NULL.

Examples

Format a time value in a standard pattern

-- Returns 13:24:33.000.
SELECT FORMAT_TIME(48273000000, '%H:%M:%S.ff3');

Embed time components in a text string

Non-specifier characters in the format string are treated as literal text.

-- Returns The time is 24:33 and the millisecond part is 000.
SELECT FORMAT_TIME(48273000000, 'The time is %M:%S and the millisecond part is ff3');

-- Returns only show 13:24.
SELECT FORMAT_TIME(48273000000, 'only show hh:mi');

Combine FORMAT_TIME with TO_TIME

Use TO_TIME to parse a time string first, then format the result.

-- Returns 15:03:01.
SELECT FORMAT_TIME(TO_TIME('15:03:01', 'hh:mi:ss'), '%H:%M:ss');

Handle NULL inputs

-- Returns NULL.
SELECT FORMAT_TIME(NULL, '%H:%M:%S.ff3');

-- Returns NULL.
SELECT FORMAT_TIME(48273000000, NULL);

Related functions

FORMAT_TIME is a time function. For more information about date and time functions in MaxCompute, see Date functions.