UTC_TIME() function in MySQL
Last Updated :
09 Oct, 2020
UTC_TIME() function in MySQL is used to check current Coordinated Universal Time (UTC) time value. It returns the UTC time value in 'HH:MM:SS' or HHMMSS format, depending on whether the function is used in string or numeric context.
Syntax :
UTC_TIME
OR
UTC_TIME()
Parameter :
This method does not accept any parameter.
Returns :
It returns the current UTC time value.
Example-1 :
Getting the current UTC time using UTC_TIME Function.
SELECT UTC_TIME as CurrUtcTime ;
Output :
Example-2 :
Getting the current UTC time using UTC_TIME Function in numeric format.
SELECT UTC_TIME + 0 as CurrUtcTime ;
Output :
Example-3 :
The UTC_TIME function can be used to set value of columns. To demonstrate create a table named DeliveryDetails.
CREATE TABLE DeliveryDetails (
DeliveryId INT AUTO_INCREMENT,
ProductId INT NOT NULL,
ProductName VARCHAR(20) NOT NULL,
Delivered_On DATE NOT NULL,
Delivered_At TIME NOT NULL,
PRIMARY KEY(DeliveryId)
);
Here, we will use UTC_DATE and UTC_TIME function when a delivery will be completed. The value in Delivered_On column will be the value given by UTC_DATE Function and the value in Delivered_At column will be the value given by UTC_TIME Function.
INSERT INTO
DeliveryDetails(ProductId, ProductName, Delivered_On, Delivered_At)
VALUES
(900000001, 'Lenovo Legion', UTC_DATE, UTC_TIME);
Now, checking the DeliveryDetails table :
SELECT * FROM DeliveryDetails;
Output :
DeliveryId |
ProductId |
ProductName |
Delivered_On |
Delivered_At |
1 |
900000001 |
Lenovo Legion |
2020-10-08 |
18:25:59 |
Similar Reads
TIME() Function in MySQL The TIME() function in MySQL is used to extract the time portion from a date or datetime expression, returning the time in the format 'HH:MM'. This function is particularly useful when working with time components in databases, such as scheduling or logging systems. In this article, We will learn ab
4 min read
UTC_TIMESTAMP() function in MySQL UTC_TIMESTAMP() function in MySQL is used to check current Coordinated Universal Time (UTC) date and time value. It returns the current UTC date and time value in YYYY-MM-DD HH:MM:SS or YYYYMMDDHHMMSS.uuu format, depending on whether the function is used in string or numeric context. Syntax : UTC_TI
2 min read
SEC_TO_TIME() Function in MySQL SEC_TO_TIME() function : This function in MySQL is used to return a time value based on the specified seconds value. Here the returned time value will be in the format of HH:MM:SS. For example, if the specified second value is 63, this function will return "00:01:03". Syntax : SEC_TO_TIME(seconds) P
1 min read
UNIX_TIMESTAMP() function in MySQL UNIX_TIMESTAMP() : This function in MySQL helps to return a Unix timestamp. We can define a Unix timestamp as the number of seconds that have passed since â1970-01-01 00:00:00âUTC. Even if you pass the current date/time or another specified date/time, the function will return a Unix timestamp based
2 min read
UTC_DATE() function in MySQL UTC_DATE() function in MySQL is used to check current Coordinated Universal Time (UTC) date. It returns the UTC date value in 'YYYY-MM-DD' or YYYYMMDD format, depending on whether the function is used in string or numeric context. Syntax : UTC_DATE OR UTC_DATE() Parameter : This method does not acce
2 min read
TIMESTAMPDIFF() function in MYSQL TIMESTAMPDIFF() : This function in MySQL is used to return a value after subtracting a DateTime expression from another. Syntax : TIMESTAMPDIFF(unit,expr1,expr2) Parameters : It will accept three parameters. unit â It denotes the unit for the result. It can be one of the following.MICROSECOND, SECON
2 min read