My Code:
DECLARE
BEGIN
-- outputs 06-DEC-18
dbms_output.put_line(sysdate);
-- also outputs 18-DEC-06
dbms_output.put_line(to_date(sysdate,'yyyy-mm-dd hh24:mi:ss'));
END;
/
The output only shows the date. I want to get also the time.
SYSDATE returns the current date and time set for the operating system on which the database resides. The datatype of the returned value is DATE , and the format returned depends on the value of the NLS_DATE_FORMAT initialization parameter. The function requires no arguments.
CURRENT_TIMESTAMP returns the current date and time in the session time zone, in a value of datatype TIMESTAMP WITH TIME ZONE . The time zone offset reflects the current local time of the SQL session. If you omit precision, then the default is 6.
The GETDATE() function returns the current database system date and time, in a 'YYYY-MM-DD hh:mm:ss. mmm' format. Tip: Also look at the CURRENT_TIMESTAMP function.
MySQL SYSDATE() Function The SYSDATE() function returns the current date and time.
SYSDATE
does have a time component. The first one outputs 06-DEC-18
because your session's parameter NLS_DATE_FORMAT
is set to DD-MON-YY
.
You have these options.
use TO_CHAR
dbms_output.put_line(TO_CHAR(SYSDATE,'yyyy-mm-dd hh24:mi:ss'));
Modify NLS_DATE_FORMAT
to show time.
ALTER SESSION SET NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss';
BEGIN
dbms_output.put_line(SYSDATE);
END;
/
Or use SYSTIMESTAMP
to show higher precision of time like milliseconds.
BEGIN
dbms_output.put_line(SYSTIMESTAMP);
END;
/
You can use SYSTIMESTAMP
SELECT SYSTIMESTAMP
FROM DUAL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With