extract date only from given timestamp in oracle sql

前端 未结 7 1553
后悔当初
后悔当初 2021-02-13 05:34

The following query:

select cdate from rprt where cdate <= TO_CHAR(sysdate, \'YYYY/MM/DD-HH24-MI-SS-SSSSS\') and ryg=\'R\' and cnum=\'C002\';
<
7条回答
  •  生来不讨喜
    2021-02-13 06:18

    In Oracle 11g, To get the complete date from the Timestamp, use this-

    Select TRUNC(timestamp) FROM TABLE_NAME;
    

    To get the Year from the Timestamp, use this-

    Select EXTRACT(YEAR FROM TRUNC(timestamp)) from TABLE_NAME;
    

    To get the Month from the Timestamp, use this-

    Select EXTRACT(MONTH FROM TRUNC(timestamp)) from TABLE_NAME;
    

    To get the Day from the Timestamp, use this-

    Select EXTRACT(DAY FROM TRUNC(timestamp)) from TABLE_NAME;
    

提交回复
热议问题