-
oracle date in seconds
Hi,
the date in oracle is stored in seconds (like 1246067125) and i'm unable to convert it into calender date and i also need converting calender date into seconds (like 1246067125)
i tried some thing like
select to_date('01/01/1970','DD/MM/YYYY') + trunc(creation_date/86400) from table; but i'm not sure about it
BTW - how to insert calender date into oracle, where date is stored in seconds..
Thanks in advance
ram
-
Originally Posted by ramdaya
the date in oracle is stored in seconds
Since Oracle stores DATE datatype in seven bytes - Century, Year, Month, Day, Hour, Minutes, Seconds - I assume you are saying somebody designed a database where for some unknown reason decided to convert dates to seconds then store that value in a NUMBER or so datatype, is that correct?
If that's the case that person most probably created a set of functions to deal with that particular design feature -look at functions.
Pablo (Paul) Berzukov
Author of Understanding Database Administration available at amazon and other bookstores.
Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
-
Hey,
why will anyone want to store the date in secs?
-
Originally Posted by chaitanyagoa
why will anyone want to store the date in secs?
I don't know and, I don't want to know
Pablo (Paul) Berzukov
Author of Understanding Database Administration available at amazon and other bookstores.
Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
-
Not that hard
Date to seconds to date is not that complex:
Code:
SQL> SET ECHO ON VER OFF
SQL> ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS';
Session altered.
SQL> COL sec new_value sec
SQL> SELECT SYSDATE, TO_CHAR (SYSDATE, 'J') * 86400
2 + TO_CHAR (SYSDATE, 'SSSSS') sec
3 FROM DUAL;
SYSDATE SEC
------------------- -------------
2009-08-05 12:53:05 212116279985
SQL> SELECT &&sec sec,
2 TO_DATE (TRUNC (&&sec / 86400), 'J')
3 + ((&&sec - TRUNC (&&sec / 86400) * 86400) / 86400)
4 FROM DUAL;
SEC TO_DATE(TRUNC(21211
------------- -------------------
212116279985 2009-08-05 12:53:05
SQL>
"The person who says it cannot be done should not interrupt the person doing it." --Chinese Proverb
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|