In MySQL, the CURRENT_TIME
function can be used to return the current time.
This function is actually a synonym for CURTIME()
which returns the current time, so you can choose which function you prefer to use.
Both functions return 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
You can use either of the following forms:
CURRENT_TIME CURRENT_TIME([fsp])
The (optional) fsp
argument can be used to provide the fractional seconds precision. If provided, the return value will include fractional seconds up to the number provided. You can specify a fsp
value between 0
and 6
.
Therefore, if you need to specify the fractional seconds precision, you’ll need to use the second syntax.
As mentioned, you can also use the following if preferred:
CURTIME([fsp])
Example – String Context
Here’s an example of using CURRENT_TIME
in a string context.
SELECT CURRENT_TIME;
Result:
+--------------+ | CURRENT_TIME | +--------------+ | 10:02:31 | +--------------+
And here’s an example of using both forms of the syntax, side by side, along with the CURTIME()
function:
SELECT CURRENT_TIME, CURRENT_TIME(), CURTIME();
Result:
+--------------+----------------+-----------+ | CURRENT_TIME | CURRENT_TIME() | CURTIME() | +--------------+----------------+-----------+ | 10:03:07 | 10:03:07 | 10:03:07 | +--------------+----------------+-----------+
Example – Numeric Context
Here’s an example of using CURRENT_TIME
in a numeric context.
SELECT CURRENT_TIME + 0;
Result:
+------------------+ | CURRENT_TIME + 0 | +------------------+ | 100425 | +------------------+
In this example I added zero to the time. But I could also have added another number.
Example – Fractional Seconds Precision
Here’s an example of specifying a fractional seconds precision of 6.
SELECT CURRENT_TIME(6);
Result:
+-----------------+ | CURRENT_TIME(6) | +-----------------+ | 10:05:24.091083 | +-----------------+