MySQL LOCALTIMESTAMP

MySQL LOCALTIMESTAMP or Localtimestamp() are the two Date Functions used to return the current date & time in YYYY-MM-DD HH:MM:SS. The basic syntax of the local timestamp in MySQL is as shown below:

LOCALTIMESTAMP;

LOCALTIMESTAMP();

MySQL LOCALTIMESTAMP Example

The following statements show you how to use these local timestamp functions.

TIP: Both these local timestamp Date methods are synonyms of the NOW. All these three MySQL methods return the same output.

SELECT LOCALTIMESTAMP;

SELECT LOCALTIMESTAMP();

SELECT NOW();
Example 1

As you can see from the above, the three statements return the local datetime stamp in YYYY-MM-DD HH:MM:SS format. The below statements show what happens when adding a few seconds or random value to the localtimestamp() function.

SELECT LOCALTIMESTAMP, LOCALTIMESTAMP + 22;

SELECT LOCALTIMESTAMP(), LOCALTIMESTAMP() + 15;

SELECT DATEDIFF(LOCALTIMESTAMP(), '2019-01-01');
MySQL LOCALTIMESTAMP Function 2

From the above screenshot, you can see the function added those extra seconds and displayed the date in YYYYMMDDHHMMSS string format. Within the last statement, we used the Datediff function to find the difference between the local timestamp and the custom date ‘2019-01-01.’