sqlcmd.net validated sql reference
beginner date-time MySQL MariaDB SQL Server PostgreSQL SQLite

Get The Current Date And Time

Return the current date and time using `CURRENT_TIMESTAMP` or engine-specific functions.

Docker-validated Not currently validation-green

Select the current timestamp

The returned value changes every time the query runs. MySQL and MariaDB return a DATETIME with second precision. SQL Server returns a DATETIME with milliseconds. PostgreSQL returns a TIMESTAMPTZ with a timezone offset. Use CURRENT_TIMESTAMP in DEFAULT column definitions to automatically record when rows are inserted.

Shared across supported engines.
SQL
SELECT
  CURRENT_TIMESTAMP AS now;
Returned rows for the shared example.
now
<current_timestamp>

The actual value reflects the time of execution and will differ. SQL Server includes milliseconds; PostgreSQL includes a timezone offset.

Where this command helps.

  • recording when a row was created or last modified
  • comparing a stored date against the current time

What the command is doing.

CURRENT_TIMESTAMP is the ANSI SQL standard function and works across all major engines. MySQL and PostgreSQL also support NOW(). SQL Server also supports GETDATE(). The returned value reflects the time at which the statement begins executing. Common uses include recording when a row was created or last modified.