SQL Keywords

SQL CURRENT_TIMESTAMP

What is SQL CURRENT_TIMESTAMP?

Returns the current date and time of the database server at statement execution.
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 CURRENT_TIMESTAMP: Supported by PostgreSQL, MySQL, MariaDB, SQL Server, Oracle, SQLite, Snowflake, Redshift, BigQuery, DB2, and others.

SQL CURRENT_TIMESTAMP Full Explanation

CURRENT_TIMESTAMP is a standard SQL temporal function that yields the current date and time as a TIMESTAMP value. It is evaluated once per SQL statement, meaning every reference within the same statement returns an identical value. Some engines allow an optional fractional-seconds precision, which controls the number of digits shown after the decimal point for seconds. The value reflects the session time zone unless the database stores timestamps without zone data. Unlike GETDATE() or NOW(), CURRENT_TIMESTAMP is ANSI-compliant and portable across most relational databases. Because it is nondeterministic, it cannot be used in indexes or persisted computed columns in certain systems. In read-only or replicated environments, the timestamp is still generated by the executing server, not the source replica.

SQL CURRENT_TIMESTAMP Syntax

CURRENT_TIMESTAMP;
-- or with precision
CURRENT_TIMESTAMP(3);

SQL CURRENT_TIMESTAMP Parameters

  • precision (integer) - Optional. Number of fractional seconds digits (0-6 in most systems).

Example Queries Using SQL CURRENT_TIMESTAMP

-- Insert creation time automatically
INSERT INTO orders (customer_id, created_at)
VALUES (42, CURRENT_TIMESTAMP);

-- Compare with a past timestamp
SELECT id
FROM sessions
WHERE last_active < CURRENT_TIMESTAMP - INTERVAL '30 minutes';

-- Use precision
SELECT CURRENT_TIMESTAMP(2) AS ts_precision_2;

Expected Output Using SQL CURRENT_TIMESTAMP

  • Each query returns the server's current date and time at the moment the statement starts executing
  • The value is a TIMESTAMP such as '2024-05-20 14:23:11
  • 123456'

Use Cases with SQL CURRENT_TIMESTAMP

  • Populate audit columns like created_at or updated_at
  • Log event time without client clock dependency
  • Compare current time to expiration or scheduling fields
  • Default column value in table definitions (DEFAULT CURRENT_TIMESTAMP)

Common Mistakes with SQL CURRENT_TIMESTAMP

  • Assuming it updates row by row inside the same statement; it does not
  • Forgetting that precision support varies by dialect
  • Expecting session time zone control when the database stores TIMESTAMP WITHOUT TIME ZONE
  • Using it in deterministic contexts such as indexed computed columns

Related Topics

CURRENT_DATE, CURRENT_TIME, LOCALTIMESTAMP, NOW(), GETDATE(), SYSDATETIME

First Introduced In

SQL-92

Frequently Asked Questions

What is the data type of CURRENT_TIMESTAMP?

It returns a TIMESTAMP or DATETIME type, depending on the database, including both date and time components.

How do I set a default column value to CURRENT_TIMESTAMP?

Define the column with `DEFAULT CURRENT_TIMESTAMP` in the CREATE TABLE or ALTER TABLE statement. The database will populate the column automatically on insert.

Does CURRENT_TIMESTAMP include the time zone?

The value reflects the session's time zone if the data type stores zone information. In databases that store it "without time zone", the literal does not carry zone data even though the clock uses the server time zone.

Why is CURRENT_TIMESTAMP preferred over GETDATE()?

GETDATE() is SQL Server specific, while CURRENT_TIMESTAMP is ANSI standard and portable across multiple database systems.

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!