LOCALTIME() function in MySQL is used to check current date and time value. It returns the value of current date and time in ‘YYYY-MM-DD HH:MM:SS’ format or YYYYMMDDHHMMSS.uuuuuu format, depending on whether the function is used in string or numeric context.
Syntax :
LOCALTIME OR LOCALTIME()
Parameter :
This method does not accept any parameter.
Returns :
It returns the current date and time value.
Example-1 :
Getting the current date and time using LOCALTIME Function.
SELECT LOCALTIME as CurrDateTime ;
Output :
CURRDATETIME |
---|
2020-10-15 13:33:54 |
Example-2 :
Getting the current date and time using LOCALTIME Function in numeric format.
SELECT LOCALTIME + 0 as CurrDateTime ;
Output :
CURRDATETIME |
---|
20201015133627 |
Example-3 :
The LOCALTIME 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 LOCALTIME function when a delivery will be completed. The value in Delivered_At column will be the value given by LOCALTIME Function.
INSERT INTO DeliveryDetails(ProductId, ProductName, Delivered_At) VALUES (101010101, 'Asus Rog', LOCALTIME);
Now, checking the DeliveryDetails table :
SELECT * FROM DeliveryDetails;
Output :
DELIVERYID | PRODUCTID | PRODUCTNAME | DELIVERED_AT |
---|---|---|---|
1 | 101010101 | Asus Rog | 2020-10-15 13:42:47 |