w3resource

MySQL UTC_TIME() function

UTC_TIME() function

MySQL UTC_TIME returns the current UTC time as a value in 'HH:MM:SS' or HHMMSS format depending on the context of the function i.e. in a string or numeric context.

This function is useful in -

  • UTC_TIME() is not affected by local time zones, making it useful for scenarios where consistent time measurement is required across different locations.
  • As it provides a time in UTC, it allows for consistent and accurate time comparisons regardless of the time zone settings of the server.
  • It's useful for filtering records or data based on time criteria, such as selecting records within a specific time range.
  • The UTC time format is commonly used for exchanging time-related information between different systems or applications, ensuring consistency in time representation.
  • Since UTC doesn't observe Daylight Saving Time, using UTC_TIME() helps avoid potential complications caused by changes in local time zone offsets.
  • In global systems or applications with users from various time zones, using UTC ensures that times are interpreted consistently regardless of the user's location.
  • In real-time applications where precise time measurements are crucial, UTC_TIME() ensures that the time is represented in a standardized format.

Syntax:

UTC_TIME; UTC_TIME()

Syntax Diagram: 1

MySQL UTC_TIME() Function - Syntax Diagram

Syntax Diagram: 2

MySQL UTC_TIME() Function - Syntax Diagram

MySQL Version: 8.0


Pictorial Presentation:

Pictorial Presentation of MySQL UTC_TIME() function

Example: MySQL UTC_TIME() function

The following statement will return the current UTC time.

Code:

SELECT UTC_TIME,UTC_TIME();

Output:

mysql> SELECT UTC_TIME,UTC_TIME();
+----------+------------+
| UTC_TIME | UTC_TIME() |
+----------+------------+
| 22:26:15 | 22:26:15   | 
+----------+------------+
1 row in set (0.02 sec)

Note: The above output shows the UTC time at the time of execution of the command. Values of the output of the code bellow may be different, since it will show the of UTC time of when you click View the example in browser.

Example of MySQL UTC_TIME() function in numeric format

The following statement will return the current UTC time in numeric format.

Code:

SELECT UTC_TIME()+0;

Output:

mysql> SELECT UTC_TIME()+0;
+---------------+
| UTC_TIME()+0  |
+---------------+
| 222924.000000 | 
+---------------+
1 row in set (0.01 sec)

Video Presentation:

All Date and Time Functions:

Click here to see the MySQL Date and time functions.

Previous: UTC_DATE()
Next: UTC_TIMESTAMP()



Follow us on Facebook and Twitter for latest update.