// dates & times reference

SQL SYSDATE function

Returns the current date and time on the database server. SYSDATE truncates to the second and returns the plain DATE type that still carries a time.

カテゴリ
Dates & times
Returns
DATE (with time) / TIMESTAMP WITH TIME ZONE
In this category
14 of 121

構文

SYSDATE
SYSTIMESTAMP
CURRENT_DATE / CURRENT_TIMESTAMP  -- session time zone

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

エンジンサポート

エンジンSupportメモ
SQL Server Different name or syntax GETDATE()
PostgreSQL Different name or syntax NOW() or clock_timestamp()
MySQL はい SYSDATE() exists, but it is the per-call clock; NOW() is fixed per statement
SQLite Different name or syntax datetime('now'), in UTC
Oracle はい Supported under this name.

例

Oracle

SELECT SYSDATE AS loaded_at FROM dual;

Oracle

SELECT TRUNC(SYSDATE) AS today FROM dual;

Oracle

SELECT SYSTIMESTAMP AS precise_ts FROM dual;

知っておくと便利なこと

  • SYSDATE follows the database server's operating-system clock, not the session time zone; CURRENT_DATE and CURRENT_TIMESTAMP follow the session.
  • Oracle DATE is not date-only: it stores hours, minutes and seconds. TRUNC(SYSDATE) gives today at midnight.
  • SYSDATE is evaluated once per statement, so every row in one UPDATE sees the same value.

Questions about SYSDATE

Is SYSDATE date-only?

No. Oracle's DATE type always carries a time, so WHERE order_date = SYSDATE almost never matches. Compare against TRUNC(SYSDATE) or use a range from TRUNC(SYSDATE) to TRUNC(SYSDATE) + 1.

Why does SYSDATE differ from CURRENT_TIMESTAMP?

SYSDATE reads the server clock in the server's time zone; CURRENT_TIMESTAMP uses the session time zone set by ALTER SESSION.

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.