MySQL 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 Diagram: 1
Syntax Diagram: 2
MySQL Version: 8.0
Example: MySQL UTC_TIME() function
The following statement will return the current UTC time.
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.
mysql> SELECT UTC_TIME()+0; +---------------+ | UTC_TIME()+0 | +---------------+ | 222924.000000 | +---------------+ 1 row in set (0.01 sec)
All Date and Time Functions:
Click here to see the MySQL Date and time functions.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join