MariaDB Tutorial MariaDB Advanced MariaDB Database Account Management MariaDB References

MariaDB LOCALTIMESTAMP() Function



The MariaDB LOCALTIMESTAMP() function returns the current date and time. It returns the current date and time in the following format:

  • Returns the current date and time as a 'YYYY-MM-DD HH:MM:SS' format, if used in a string context.
  • Returns the current date and time as a YYYYMMDDHHMMSS.uuuuuu format, if used in a numeric context.

The LOCALTIMESTAMP(), LOCALTIME() and CURRENT_TIMESTAMP() functions are a synonyms for the NOW() function.

Syntax

LOCALTIMESTAMP()

Parameters

No parameter is required.

Return Value

Returns the current date and time.

Example 1:

The example below shows the usage of LOCALTIMESTAMP() function.

SELECT LOCALTIMESTAMP();
Result: '2021-12-27 05:11:57'

SELECT LOCALTIMESTAMP() + 0;
Result: 20211227051157

SELECT LOCALTIMESTAMP() + 1;
Result: 20211227051158

Example 2:

Consider a database table called EmployeeLogin with the following records:

EmpIDNameLogin Stamp
1John2019-10-25 09:20:38
2Marry2019-10-25 09:21:05
3Jo2019-10-25 09:24:35
4Kim2019-10-25 09:25:24
5Ramesh2019-10-25 09:27:16

To insert a new record in this table, the following query can be used.

INSERT INTO EmployeeLogin 
VALUES (6, 'Suresh', LOCALTIMESTAMP());

-- see the result
SELECT * FROM EmployeeLogin;

This will produce a result similar to:

EmpIDNameLogin Stamp
1John2019-10-25 09:20:38
2Marry2019-10-25 09:21:05
3Jo2019-10-25 09:24:35
4Kim2019-10-25 09:25:24
5Ramesh2019-10-25 09:27:16
6Suresh2019-10-25 09:28:19

❮ MariaDB Functions

5