LOCALTIMESTAMP Examples – MySQL

The MySQL LOCALTIMESTAMP function is a synonym for the NOW() function. It returns the current date and time.

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:

LOCALTIMESTAMP
LOCALTIMESTAMP([fsp])

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

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 LOCALTIMESTAMP;

Result:

+---------------------+
| LOCALTIMESTAMP      |
+---------------------+
| 2018-06-28 15:50:05 |
+---------------------+

Fractional Seconds Precision

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

SELECT LOCALTIMESTAMP(6);

Result:

+----------------------------+
| LOCALTIMESTAMP(6)          |
+----------------------------+
| 2018-06-28 15:50:17.206091 |
+----------------------------+

Numeric Context

Here’s an example of using the LOCALTIMESTAMP function in a numeric context.

SELECT LOCALTIMESTAMP + 0;

Result:

+--------------------+
| LOCALTIMESTAMP + 0 |
+--------------------+
|     20180628155032 |
+--------------------+

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

SELECT 
    LOCALTIMESTAMP + 0,
    LOCALTIMESTAMP + 5;

Result:

+--------------------+--------------------+
| LOCALTIMESTAMP + 0 | LOCALTIMESTAMP + 5 |
+--------------------+--------------------+
|     20180628155045 |     20180628155050 |
+--------------------+--------------------+