Extract time part from TimeStamp column in ORACLE

前端 未结 7 1652
我寻月下人不归
我寻月下人不归 2021-01-02 01:14

Currently I\'m using MyTimeStampField-TRUNC(MyTimeStampField) to extract the time part from a timestamp column in Oracle.

SELECT CURRENT_TIMEST         


        
相关标签:
7条回答
  • 2021-01-02 01:58
    select TO_DATE(TO_CHAR(SYSDATE,'hh24:mi:ss'),'hh24:mi:ss') from dual
    

    This gives the timestamp for 1hour less than the actual.

    0 讨论(0)
  • 2021-01-02 01:59

    This may help:

    Select EXTRACT(HOUR FROM (SYSDATE - trunc(sysdate)) DAY TO SECOND ) From dual;
    
    0 讨论(0)
  • 2021-01-02 02:06
    select hour(CURRENT_TIMESTAMP)
    
    0 讨论(0)
  • 2021-01-02 02:07

    You could always do something like:

    select TO_DATE(TO_CHAR(SYSDATE,'hh24:mi:ss'),'hh24:mi:ss') from dual
    

    I believe this will work with timestamps as well.

    0 讨论(0)
  • 2021-01-02 02:09

    I think the method in question is shorter and faster than in both answers. Cause it involves just two math operations and no complex parsing, formatting and conversion.

    0 讨论(0)
  • 2021-01-02 02:17

    You want just date then use

    to_char(cast(SYSDATE as date),'DD-MM-YYYY')
    

    and if you want just time then use

    to_char(cast(SYSDATE as date),'hh24:mi:ss')
    

    the parameters are making all the changed

    'DD-MM-YYYY'
    

    and

    'hh24:mi:ss'
    
    0 讨论(0)
提交回复
热议问题