11.17. Date Functions

11.17.1. SYSDATE

FUNCTION SYSDATE RETURN DATE;

This function returns the current date and time. It can be used in any PL/SQL expressions including initialization of variables. SYSDATE evaluates to a DATE type. If you assign SYSDATE to a string, Oracle will do an implicit conversion.

DECLARE
    today DATE := SYSDATE;
BEGIN
    NULL;
END;

You can set a default display format for your session with the ALTER SESSION statement.

SQL> ALTER SESSION SET
     NLS_DATE_FORMAT='dd-mon-yyyy hh24:mi:ss';

The session default display now includes date and time.

SQL> select sysdate from dual;

SYSDATE
--------------------
06-may-2004 12:47:07

The TRUNC function truncates a date to zero hours, minutes, and seconds. This is the earliest time possible ...

Get Programming Oracle® Triggers and Stored Procedures, Third Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.