LOCALTIME() function in MySQL
Last Updated :
19 Oct, 2020
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 |
Similar Reads
LOCALTIMESTAMP() Function in MySQL LOCALTIMESTAMP() function : This function in MySQL is used to return the current date and time in the format of "YYYY-MM-DD HH-MM-SS" (string) or as YYYYMMDDHHMMSS.uuuuuu (numeric). Syntax : LOCALTIMESTAMP OR LOCALTIMESTAMP() Parameter : This method does not accept any parameters. Returns : It retur
1 min read
MySQL LOCATE() Function MySQL LOCATE() function is used to find the position of a substring in a string. It returns the location of the first occurrence of the substring in the string. If the substring is not present in the string, then it will return 0. LOCATE() function in MySQL does not perform a case-sensitive search.
2 min read
MAKETIME() Function in MySQL MAKETIME() function : This function in MySQL is used to create and return a time value based on specified hour, minute, and second value. In MySQL's TIME value limit is 838:59:59. Syntax : MAKETIME(hour, minute, second) Parameters : This method accepts three parameters as given below - hour : Specif
1 min read
LEAST() Function in MySQL The LEAST() function in MySQL is a versatile tool that returns the smallest (minimum) value from a list of expressions. It can be used with numbers, strings, or even columns of data to find the minimum value according to their data type.In this article, We will learn about LEAST() Function in MySQL
4 min read
LEFT() Function in MySQL The LEFT() function in MySQL is used to extract a specified number of characters from the left side of a given string. It uses its second argument to decide, how many characters it should return. Syntax: LEFT (str, len)Parameter: This function accepts two parameters as mentioned above and described
1 min read