The CURTIME() function in MySQL returns the current time in the format HH:MM:SS (string) or as a numeric value in the HHMMSS.uuuuuu format.
Definition and Usage
- The
CURTIME()function returns the current time.
Syntax
CURTIME()
Technical Details
- Works in: From MySQL 4.0
- Return Value: Returns the current time in the format
HH:MM:SS.
Examples
Example 1: Return the current time
SELECT CURTIME();
Output:
14:30:15
This query will return the current time in the HH:MM:SS format.
Example 2: Return the current time + 1 second
SELECT CURTIME() + 1;
Output:
14:30:16
This query adds 1 second to the current time and returns the updated time.
Related Functions
CURRENT_TIME(): Equivalent toCURTIME().NOW(): Returns the current date and time (equivalent toCURRENT_TIMESTAMP()).CURRENT_TIMESTAMP(): Returns the current date and time.CURDATE(): Returns the current date.CURRENT_DATE(): Returns the current date (equivalent toCURDATE()).
Use Cases
- Time-based Calculations: Useful when you need to calculate or compare times in queries.
- Logging Events: When you need to store the time of an event or action.
- Displaying Current Time: You can use
CURTIME()when you need to show the current time in a report or UI.