MySQL UTC_TIMESTAMP() Function
In MySQL, the UTC_TIMESTAMP() function returns the current UTC date and time.
If the UTC_TIMESTAMP() function is used in a string context, the returned value is in 'YYYY-MM-DD hh:mm:ss' format, and if used in a numeric context, the returned value is in YYYYMMDDhhmmss format.
UTC_TIMESTAMP() Syntax
Here is the syntax of MySQL UTC_TIMESTAMP() function:
UTC_TIMESTAMP()
or
UTC_TIMESTAMP(fsp)
Parameters
fsp- Optional. The fractional seconds precision from
0to6. The default is0.
UTC_TIMESTAMP() Examples
Returns UTC datetime
Returns the current UTC date and time.
SELECT UTC_TIMESTAMP(), UTC_TIMESTAMP() + 0;
+---------------------+---------------------+
| UTC_TIMESTAMP() | UTC_TIMESTAMP() + 0 |
+---------------------+---------------------+
| 2022-04-16 14:36:21 | 20220416143621 |
+---------------------+---------------------+Note: UTC_TIMESTAMP() + 0The result is in the hhmmss format.
UTC_TIMESTAMP() + NMeans the current time plus N seconds . For example, add 1 second to the current system time:
SELECT UTC_TIMESTAMP(), UTC_TIMESTAMP() + 1;
+---------------------+---------------------+
| UTC_TIMESTAMP() | UTC_TIMESTAMP() + 1 |
+---------------------+---------------------+
| 2022-04-16 14:36:36 | 20220416143637 |
+---------------------+---------------------+fractional seconds
SELECT UTC_TIMESTAMP(1), UTC_TIMESTAMP(6);
+-----------------------+----------------------------+
| UTC_TIMESTAMP(1) | UTC_TIMESTAMP(6) |
+-----------------------+----------------------------+
| 2022-04-16 14:43:45.6 | 2022-04-16 14:43:45.601999 |
+-----------------------+----------------------------+