// dates & times reference

SQL LOCALTIMESTAMP function

Returns the current date and time as a plain timestamp, without any time-zone information, unlike CURRENT_TIMESTAMP on zone-aware engines.

Kategorie
Dates & times
Returns
timestamp
In this category
17 of 121

Syntax

LOCALTIMESTAMP
LOCALTIMESTAMP(p)
NOW()  -- MySQL synonym

Each block is a separate form. The support table and the examples show which engine takes which.

Engine-Unterstützung

EngineSupportNotizen
SQL Server Different name or syntax GETDATE(); no LOCALTIMESTAMP keyword
PostgreSQL Ja Supported under this name.
MySQL Ja Supported under this name.
SQLite Different name or syntax no keyword; datetime('now', 'localtime')
Oracle Ja Supported under this name.

Beispiele

PostgreSQL

SELECT LOCALTIMESTAMP(3) AS loaded_at;

MySQL

SELECT LOCALTIMESTAMP AS loaded_at;

Oracle

SELECT LOCALTIMESTAMP FROM dual;

Gut zu wissen

  • On PostgreSQL the difference is real: CURRENT_TIMESTAMP is timestamptz, LOCALTIMESTAMP is timestamp; storing the wrong one bakes the session zone into the data.
  • MySQL treats CURRENT_TIMESTAMP, NOW() and LOCALTIMESTAMP as exact synonyms; all three return the session time_zone's wall clock.
  • LOCALTIMESTAMP is the transaction start time on PostgreSQL; clock_timestamp() is the moving wall clock.

Questions about LOCALTIMESTAMP

When should I use LOCALTIMESTAMP instead of CURRENT_TIMESTAMP?

Only when you genuinely want zone-less wall time. For event timestamps, zone-aware CURRENT_TIMESTAMP (or UTC) survives time-zone changes better.

Is LOCALTIMESTAMP available on SQL Server?

No keyword. GETDATE() or SYSDATETIME() return the server's local wall time as a zone-less value, which is the same idea (SQL Server has no per-session zone).

Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.

Cheat sheets for the engines that have it: SQL Server, PostgreSQL, MySQL, SQLite, Oracle.

// fewer lookups

Functions your engine actually has

SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.