In MariaDB, UTC_TIMESTAMP()
is a built-in date and time function that returns the current UTC date and time.
The result is returned inĀ ‘YYYY-MM-DD HH:MM:SS’ or YYYYMMDDHHMMSS.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_TIMESTAMP()
can be called in the following two ways:
UTC_TIMESTAMP
UTC_TIMESTAMP([precision])
Where precision
is an optional argument that specifies the microsecond precision to use.
Example
Here’s an example:
SELECT
UTC_TIMESTAMP,
UTC_TIMESTAMP();
Result:
+---------------------+---------------------+ | UTC_TIMESTAMP | UTC_TIMESTAMP() | +---------------------+---------------------+ | 2021-06-01 22:54:53 | 2021-06-01 22:54:53 | +---------------------+---------------------+
Precision
Here’s an example that specifies the precision to use:
SELECT
UTC_TIMESTAMP(3),
UTC_TIMESTAMP(6);
Result:
+-------------------------+----------------------------+ | UTC_TIMESTAMP(3) | UTC_TIMESTAMP(6) | +-------------------------+----------------------------+ | 2021-06-01 22:55:09.880 | 2021-06-01 22:55:09.880201 | +-------------------------+----------------------------+
Numeric Context
When used in a numeric context, UTC_TIMESTAMP()
returns its value in YYYYMMDDHHMMSS.uuuuuu format:
SELECT
UTC_TIMESTAMP(6),
UTC_TIMESTAMP(6) + 0;
Result:
+----------------------------+-----------------------+ | UTC_TIMESTAMP(6) | UTC_TIMESTAMP(6) + 0 | +----------------------------+-----------------------+ | 2021-06-01 23:00:50.105119 | 20210601230050.105119 | +----------------------------+-----------------------+
Invalid Arguments
Passing an invalid argument results in an error:
SELECT UTC_TIMESTAMP('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