extract date only from given timestamp in oracle sql

前端 未结 7 1547
后悔当初
后悔当初 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:10

    try this type of format:

    SELECT to_char(sysdate,'dd-mm-rrrr') FROM dual
    
    0 讨论(0)
  • 2021-02-13 06:12

    Convert Timestamp to Date as mentioned below, it will work for sure -

    select TO_DATE(TO_CHAR(TO_TIMESTAMP ('2015-04-15 18:00:22.000', 'YYYY-MM-DD HH24:MI:SS.FF'),'MM/DD/YYYY HH24:MI:SS'),'MM/DD/YYYY HH24:MI:SS') dt from dual
    
    0 讨论(0)
  • 2021-02-13 06:17

    Use the function cast() to convert from timestamp to date

    select to_char(cast(sysdate as date),'DD-MM-YYYY') from dual;
    

    For more info of function cast oracle11g http://docs.oracle.com/cd/B28359_01/server.111/b28286/functions016.htm#SQLRF51256

    0 讨论(0)
  • 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;
    
    0 讨论(0)
  • 2021-02-13 06:18

    This format worked for me, for the mentioned date format i.e. MM/DD/YYYY

    SELECT to_char(query_date,'MM/DD/YYYY') as query_date 
    FROM QMS_INVOICE_TABLE;
    
    0 讨论(0)
  • 2021-02-13 06:28

    If you want the value from your timestamp column to come back as a date datatype, use something like this:

    select trunc(my_timestamp_column,'dd') as my_date_column from my_table;
    
    0 讨论(0)
提交回复
热议问题