CURTIME() function in MySQL
Last Updated :
27 Nov, 2020
CURTIME() function in MySQL is used to check the current time. It returns the current time as a value in ‘hh:mm:ss’ or ‘hhmmss’ format, depending on whether the function is used in a string or numeric context.
Syntax :
CURTIME(fsp)
Parameters :
This method accepts only one parameter.
fsp –
It specifies the returned fractional seconds precision. If the user omits the precision argument, the result will exclude precision.
Returns :
It returns the current time.
Example-1:
Getting the current time using CURTIME Function.
SELECT CURTIME() as Curr_time ;
Output :
Example 2:
Getting the current time using CURTIME Function with precision is set to 3.
SELECT CURTIME(3) as Curr_time ;
Output :
Example-3:
Getting the current time using CURTIME Function in numeric format.
SELECT CURTIME() + 0 as Curr_time ;
Output :
Example-4:
The CURTIME function can be used to set the 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 TIME NOT NULL,
Delivered_On DATE NOT NULL,
PRIMARY KEY(DeliveryId)
);
Here, we will use CURDATE and CURTIME function when a delivery will be completed. The value in the Delivered_At column will be the value given by CURTIME and the value in the Delivered_On column will be the value given by the CURDATE Function.
INSERT INTO
DeliveryDetails(ProductId, ProductName, Delivered_At, Delivered_On)
VALUES
(12345, 'Dell Latitude', CURTIME(), CURDATE() );
Now, checking the DeliveryDetails table :
SELECT * FROM DeliveryDetails;
Output :
DELIVERYID |
PRODUCTID |
PRODUCTNAME |
DELIVERED_AT |
DELIVERED_ON |
1 |
12345 |
Dell Latitude |
13:17:22 |
2020-11-20 |
Share your thoughts in the comments
Please Login to comment...