This content has been marked as final. Show 4 replies
user9546145 wrote:Be careful! In Oracle, TIMESTAMP means a datatype, similar to but distinct from DATE. You'll avoid confusion if you don't use the word "timestamp" to mean anything else.
I would like to know how to extract the timestamp alone from DATE datatype?
There is a built-in function, TO_CHAR:
Depending on how you plan to use the time, TRUNC is another handy built-in function:
TO_CHAR (dt_col, 'HH24:MI:SS')
is a NUMBER (not less than 0, but less than 1) which is suitable for many tasks, such as finding the average time.
dt_col - TRUNC (dt_col)
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables, and also post the results you want from that data.
Explain, using specific examples, how you get those results from that data.
Always say which version of Oracle you're using.
TO_CHAR is your builtin function.
SQL> -- generating sample date: SQL> with t as ( 2 select to_date('27-SEP-2011 23:59:00', 'dd-mon-yyyy hh24:mi:ss') dt from dual 3 ) 4 -- 5 -- actual query: 6 -- 7 select to_char(dt, 'hh24:mi:ss') 8 from t; TO_CHAR( -------- 23:59:00 1 row selected.
You may use to_date and to_char function together, it your parameter is text:
E.g: if you passing '27-SEP-2011 23:59:00' as a varchar2 datatype then first convert it into date and then extract the time from it; for that use this command:
SQL> select to_char(to_date('27-SEP-2011 23:59:00','dd-mm-yyyy HH24:MI:SS'),'HH24:MI:SS AM') time from dual;
if you already passing the date type as parameter then just use to_char function for extract the time from it.
Select to_char(sysdate,'HH24:MI:SS AM') from dual;
the AM will indicates that either its morning time or afternoon time automatically.
I hope this is your answer
Thanks all for your inputs..!!:)