Oracle comparing timestamp with date

后端 未结 3 643
抹茶落季
抹茶落季 2020-12-29 03:31

I have a timestamp field and I just want to compare the date part of it in my query in Oracle

How do I do that,

SELECT *
FROM Table1
WHERE date(field         


        
相关标签:
3条回答
  • 2020-12-29 04:10

    You can truncate the date part:

    select * from table1 where trunc(field1) = to_date('2012-01-01', 'YYYY-MM-DD')
    

    The trouble with this approach is that any index on field1 wouldn't be used due to the function call.

    Alternatively (and more index friendly)

    select * from table1 
     where field1 >= to_timestamp('2012-01-01', 'YYYY-MM-DD') 
       and field1 < to_timestamp('2012-01-02', 'YYYY-MM-DD')
    
    0 讨论(0)
  • 2020-12-29 04:20

    You can truncate the date

    SELECT *
    FROM Table1
    WHERE trunc(field1) = to_Date('2012-01-01','YYY-MM-DD')
    

    Look at the SQL Fiddle for more examples.

    0 讨论(0)
  • 2020-12-29 04:28

    to_date format worked for me. Please consider the date formats: MON-, MM, ., -.

    t.start_date >= to_date('14.11.2016 04:01:39', 'DD.MM.YYYY HH24:MI:SS')
    t.start_date <=to_date('14.11.2016 04:10:07', 'DD.MM.YYYY HH24:MI:SS')
    
    0 讨论(0)
提交回复
热议问题