Summary: in this tutorial, you will learn how to use MySQL UTC_TIME() to get the current time in UTC.
Introduction MySQL UTC_TIME() function
The UTC_TIME() function returns the current time in Coordinated Universal Time (UTC).
Here’s the syntax of the UTC_TIME() function:
UTC_TIME()Code language: SQL (Structured Query Language) (sql)The UTC_TIME() has no parameter and returns a string in the hh:mm:ss or a number that represents the current time in UTC.
In practice, you use the UTC_TIME() function to handle time consistently regardless of the server’s timezone settings.
MySQL UTC_TIME() function examples
Let’s take some examples of using the UTC_TIME() function.
1) Simple UTC_TIME() function example
The following example uses the UTC_TIME() function to show the current UTC time:
SELECT UTC_TIME();Code language: SQL (Structured Query Language) (sql)Output:
+------------+
| UTC_TIME() |
+------------+
| 02:10:33 |
+------------+
1 row in set (0.00 sec)Code language: SQL (Structured Query Language) (sql)2) Using UTC_TIME() in numeric context
The following example shows how to use the UTC_TIME() function in numeric contexts:
SELECT UTC_TIME() + 0;Code language: SQL (Structured Query Language) (sql)Output:
+----------------+
| UTC_TIME() + 0 |
+----------------+
| 21411 |
+----------------+
1 row in set (0.00 sec)Code language: SQL (Structured Query Language) (sql)In this example, we use the UTC_TIME() function to get the current time and add 0 to it to force the result of the query as a number.
The result is 21411 consisting of 2: hours, 14: minutes, and 11: seconds.
Summary
- Use
UTC_TIME()to get the current time in UTC.