How to Get Current Date in PL/SQL?

The following are the examples to get the current date in PL/SQL.

Examples To Get The Current Date in PL/SQL

1. Using Sysdate Function

SET SERVEROUTPUT ON;

DECLARE
d_current_date DATE;
BEGIN
d_current_date := SYSDATE;
DBMS_OUTPUT.put_line ('The Date today is: ' || d_current_date);
END;
/

Output:

The Date today is: 19-AUG-18
PL/SQL procedure successfully completed.

2. Using CURRENT_DATE Function

SET SERVEROUTPUT ON;

DECLARE
d_current_date DATE;
BEGIN
d_current_date := CURRENT_DATE;
DBMS_OUTPUT.put_line ('The Date today is: ' || d_current_date);
END;
/

Output:

The Date today is: 19-AUG-18
PL/SQL procedure successfully completed.

3. Get Current Date with Time Using To_Char() Function

SET SERVEROUTPUT ON;

DECLARE
d_current_date DATE;
BEGIN
d_current_date := CURRENT_DATE;
DBMS_OUTPUT.put_line ('The Date today is: ' || to_char(d_current_date, 'DD/MM/YYYY HH24:MI:SS'));
END;
/

Output:

The Date today is: 19/08/2018 16:54:52
PL/SQL procedure successfully completed.

See also:

Get more Vinish.dev tutorials on Google

See my articles more often when you search Google.

Vinish Kapoor
Vinish Kapoor

An Oracle ACE, author of four books on Oracle APEX, SQL and PL/SQL, and Oracle Forms, and a software developer building Oracle database applications since 2001.

guest

0 Comments
Oldest
Newest Most Voted