Open In App

UTC_TIME() function in MySQL

Improve
Improve
Like Article
Like
Save
Share
Report

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 :

CurrUtcTime
18:11:35

Example-2 :
Getting the current UTC time using UTC_TIME Function in numeric format.

SELECT UTC_TIME + 0 as CurrUtcTime ;

Output :

CurrUtcTime
181250

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

Last Updated : 09 Oct, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads