Open In App

UTC_TIMESTAMP() function in MySQL

Last Updated : 13 Oct, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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_TIMESTAMP
 OR
UTC_TIMESTAMP()

Parameter :
This method does not accept any parameter.

Returns :
It returns the current UTC date and time value.

Example-1 :
Getting the current UTC date and time using UTC_TIMESTAMP Function.

SELECT UTC_TIMESTAMP as CurrUtcDateAndTime ;

Output :

CurrUtcDateAndTime
2020-10-09 18:08:13

Example-2 :
Getting the current UTC date and time using UTC_TIMESTAMP Function in numeric format.

SELECT UTC_TIMESTAMP + 0 as CurrUtcDateAndTime ;

Output :

CurrUtcDateAndTime
20201009180940

Example-3 :
The UTC_TIMESTAMP 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_At TIMESTAMP NOT NULL,
PRIMARY KEY(DeliveryId)
);

Here, we will use UTC_TIMESTAMP function when a delivery will be completed. The value in Delivered_At column will be the value given by UTC_TIMESTAMP Function.

INSERT INTO  
DeliveryDetails(ProductId, ProductName, Delivered_At)
VALUES
(1010001, 'Dell  Inspirion', UTC_TIMESTAMP );

Now, checking the DeliveryDetails table :

SELECT * FROM DeliveryDetails;

Output :

DeliveryId ProductId ProductName Delivered_At
1 1010001 Dell Inspirion 2020-10-09 18:17:31

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads