SQL Keywords

SQL LOCALTIMESTAMP

What is SQL LOCALTIMESTAMP?

Returns the current date and time of the database session, without time-zone adjustment.
Sign up to get up to date news on SQL keywords
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Compatible dialects for SQL LOCALTIMESTAMP: PostgreSQL, Oracle, MySQL (synonym), MariaDB, Firebird, H2, DB2. Not supported in SQL Server or SQLite.

SQL LOCALTIMESTAMP Full Explanation

LOCALTIMESTAMP is an ANSI SQL standard datetime function that yields the current timestamp based on the database server\u2019s local clock, but does not include a time zone component. Unlike CURRENT_TIMESTAMP, which may return a value with time zone, LOCALTIMESTAMP delivers a timestamp \"without time zone\" (PostgreSQL) or a DATETIME value (MySQL, Oracle). The value is computed at statement start, so multiple calls within a single statement return the same result. Precision (fractional seconds) follows the database default or an optional precision argument where supported. Because the function is deterministic within a statement, it is safe for default column values, auditing, and temporal calculations where time zone conversion is not desired.

SQL LOCALTIMESTAMP Syntax

-- zero precision
LOCALTIMESTAMP;

-- explicit fractional-second precision (if supported)
LOCALTIMESTAMP(3);

SQL LOCALTIMESTAMP Parameters

Example Queries Using SQL LOCALTIMESTAMP

-- 1. Quick check of server time
SELECT LOCALTIMESTAMP;

-- 2. Use as a default value when creating a table
CREATE TABLE audit_log (
  id           SERIAL PRIMARY KEY,
  event        TEXT NOT NULL,
  created_at   TIMESTAMP DEFAULT LOCALTIMESTAMP
);

-- 3. Insert a record and let LOCALTIMESTAMP populate the column
INSERT INTO audit_log(event) VALUES ('user_login');

-- 4. Compare current local time to a row\u2019s timestamp
SELECT id, event
FROM   audit_log
WHERE  created_at >= LOCALTIMESTAMP - INTERVAL '1 day';

Expected Output Using SQL LOCALTIMESTAMP

  • Each call returns the current local timestamp at the moment the statement starts; inserted rows inherit that timestamp automatically when defined as DEFAULT

Use Cases with SQL LOCALTIMESTAMP

  • Capture creation time of rows without storing time zone
  • Build audit tables where all events follow server time
  • Replace NOW() or CURRENT_TIMESTAMP when time zone information is unnecessary or unwanted
  • Snapshot current time inside stored procedures and functions

Common Mistakes with SQL LOCALTIMESTAMP

  • Adding parentheses like LOCALTIMESTAMP() in databases that disallow it
  • Expecting a time zone offset in the returned value
  • Assuming it updates for every row in a multirow statement (it does not)
  • Using it in SQL Server or SQLite, which do not support the keyword

Related Topics

CURRENT_TIMESTAMP, LOCALTIME, NOW(), SYSDATE, TIMEZONE

First Introduced In

SQL:1999

Frequently Asked Questions

What does LOCALTIMESTAMP return?

It returns the current date and time from the server clock without any time zone offset.

How is LOCALTIMESTAMP different from CURRENT_TIMESTAMP?

CURRENT_TIMESTAMP can include a time zone. LOCALTIMESTAMP never does, making it ideal when you want a plain timestamp.

Can I call LOCALTIMESTAMP with parentheses?

In most databases you must omit parentheses unless supplying a precision value, for example LOCALTIMESTAMP(3).

Is LOCALTIMESTAMP available in SQL Server or SQLite?

No. Use GETDATE() in SQL Server or datetime('now') in SQLite instead.

Sign up to get up to date news on SQL keywords
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.
Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo

Check out other commonly used SQL Keywords!