How UTC_TIME() Works in MariaDB

In MariaDB, UTC_TIME() is a built-in date and time function that returns the current UTC time.

The result is returned in ‘HH:MM:SS’ or HHMMSS.uuuuuu format, depending on whether the function is used in a string or numeric context.

UTC stands for Coordinated Universal Time, and is the world standard for regulating time.

Syntax

UTC_TIME() can be called in the following two ways:

UTC_TIME
UTC_TIME([precision])

Where precision is an optional argument that specifies the microsecond precision to use.

Example

Here’s an example:

SELECT 
    UTC_TIME,
    UTC_TIME();

Result:

+----------+------------+
| UTC_TIME | UTC_TIME() |
+----------+------------+
| 00:17:09 | 00:17:09   |
+----------+------------+

Precision

Here’s an example that specifies the precision to use:

SELECT 
    UTC_TIME(3),
    UTC_TIME(6);

Result:

+--------------+-----------------+
| UTC_TIME(3)  | UTC_TIME(6)     |
+--------------+-----------------+
| 00:18:21.667 | 00:18:21.667957 |
+--------------+-----------------+

Numeric Context

When used in a numeric context, UTC_TIME() returns its value in HHMMSS.uuuuuu format:

SELECT 
    UTC_TIME(6),
    UTC_TIME(6) + 0;

Result:

+-----------------+-----------------+
| UTC_TIME(6)     | UTC_TIME(6) + 0 |
+-----------------+-----------------+
| 23:01:18.921377 |   230118.921377 |
+-----------------+-----------------+

Invalid Arguments

Passing an invalid argument results in an error:

SELECT UTC_TIME('Six');

Result:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''Six')' at line 1