CURRENT_TIMESTAMP Examples – MySQL

The MySQL CURRENT_TIMESTAMP function returns the current date and time.

This function is actually a synonym for the NOW() function.

The value is returned in ‘YYYY-MM-DD HH:MM:SS’ or YYYYMMDDHHMMSS format, depending on whether the function is used in a string or numeric context.

Syntax

You can use either of the following two forms:

CURRENT_TIMESTAMP
CURRENT_TIMESTAMP([fsp])

Where the (optional) fsp argument specifies the fractional seconds precision for the return value.

Obviously, if you need to provide the fractional seconds precision, you’ll need to use the second form.

Example

Here’s an example to demonstrate.

SELECT CURRENT_TIMESTAMP;

Result:

+---------------------+
| CURRENT_TIMESTAMP   |
+---------------------+
| 2018-06-23 11:32:15 |
+---------------------+

Fractional Seconds Precision

Here’s an example of using the fsp argument to specify the fractional seconds precision for the return value.

SELECT CURRENT_TIMESTAMP(6);

Result:

+----------------------------+
| CURRENT_TIMESTAMP(6)       |
+----------------------------+
| 2018-06-23 11:32:33.766154 |
+----------------------------+

Numeric Context

Here’s an example of using the CURRENT_TIMESTAMP() function in a numeric context.

SELECT CURRENT_TIMESTAMP() + 0;

Result:

+-------------------------+
| CURRENT_TIMESTAMP() + 0 |
+-------------------------+
|          20180623113258 |
+-------------------------+

You can also use a nonzero value to add or subtract from the return value.