This content has been marked as final. Show 7 replies
user10484841 wrote:Simply use SYSDATE. Why are you TO_DATE'ing something that is already a date ?
I'm trying to insert into the table's row the default time in which the data is added. I'm trying to do something like
"INSERT INTO TEST (DATESS) VALUES (to_date(sysdate, 'yyyy/mm/dd:hh:mi:ssam'))"
But this don't work. is there other more efficient way to insert the current time in which I add the new row to the table?
Re: How To Format Sysdate
Read the reply by SomeoneElse
You don't format date types. They are stored in an internal format that you and I generally don't care about.When you say you want a date to appear in a certain format, you're taking a date type and converting it to a character string.
user10484841 wrote:Oracle always stores dates in its own internal format. to_date() is used to tell oracle how to parse a string of characters that we humans recognize as a date. If you just gave it a string of "05-04-09" how would it know what is what? That's what the to_date function is for. Conversly, when retrieving a DATE type you use to_char to tell oracle how you want the internal representation converted to a character string that you can use. Try the following:
Ok, but is it possible to insert the sysdate into this format yyyy/mm/dd:hh:mi:ssam?
select sysdate from dual; select to_char(sysdate,'dd-mm-yy') from dual; select to_char(sysdate,'mon-yyyy') from dual; select to_char(sysdate,'dd-mon-yy') from dual; select to_char(sysdate,'dd-Mon-yy hh:24:mi:ss') from dual; alter session set nls_date_format='dd-mm-yy'; select sysdate from dual; alter session set nls_date_format='mon-yyyy'; select sysdate from dual; alter session set nls_date_format='dd-mon-yy'; select sysdate from dual; alter session set nls_date_format='dd-Mon-yy hh24:mi:ss'; select sysdate from dual;