In Oracle SQL: How do you insert the current date + time into a table?

Tikkaty picture Tikkaty · Oct 5, 2015 · Viewed 99.1k times · Source

I've written below code, but it only seems to insert the current date and not the current time. Anyone knows how to do that?

insert into errortable
(dateupdated,table1id)
values
(TO_DATE(sysdate, 'dd/mm/yyyy hh24:mi:ss'),1083);

Answer

Gordon Linoff picture Gordon Linoff · Oct 5, 2015

It only seems to because that is what it is printing out. But actually, you shouldn't write the logic this way. This is equivalent:

insert into errortable (dateupdated, table1id)
    values (sysdate, 1083);

It seems silly to convert the system date to a string just to convert it back to a date.

If you want to see the full date, then you can do:

select TO_CHAR(dateupdated, 'YYYY-MM-DD HH24:MI:SS'), table1id
from errortable;