CURTIME() Examples – MySQL

In MySQL, the CURTIME() function is used to return the current time.

More specifically, it returns the current date as a value in ‘HH:MM:SS’ or HHMMSS format, depending on whether the function is used in a string or numeric context.

Syntax

The syntax goes like this:

CURTIME([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.

However, as mentioned, the data type of the return value will depend on the context with which it’s used. More on this below.

You can also use either of the following if you prefer:

CURRENT_TIME
CURRENT_TIME()

These are synonyms for CURTIME().

Example – String Context

Here’s an example of using CURTIME() in a string context.

SELECT CURTIME();

Result:

+-----------+
| CURTIME() |
+-----------+
| 09:49:17  |
+-----------+

Example – Numeric Context

Here’s an example of using CURDATE() in a numeric context.

SELECT CURTIME() + 0;

Result:

+---------------+
| CURTIME() + 0 |
+---------------+
|         94935 |
+---------------+

In this example I added zero to the time. But I could also have added another value.

Example – Fractional Seconds Precision

Here’s an example of specifying that the return value should have 6 fractional seconds.

SELECT CURTIME(6);

Result:

+-----------------+
| CURTIME(6)      |
+-----------------+
| 09:52:44.979157 |
+-----------------+

CURRENT_TIME and CURRENT_TIME()

As mentioned, both CURRENT_TIME and CURRENT_TIME() are synonyms for CURTIME().

Here’s an example with all three together:

SELECT 
    CURRENT_TIME,
    CURRENT_TIME(),
    CURTIME();

Result:

+--------------+----------------+-----------+
| CURRENT_TIME | CURRENT_TIME() | CURTIME() |
+--------------+----------------+-----------+
| 09:53:29     | 09:53:29       | 09:53:29  |
+--------------+----------------+-----------+