Oracle: SQL select date with timestamp

前端 未结 2 556
[愿得一人]
[愿得一人] 2021-02-06 13:31

I have the following data:

SQL> select * from booking_session;

BK_ID|BK_DATE
-----|-------------------------
    1|18-MAR-12 10.00.00.000000
    2|18-MAR-12          


        
相关标签:
2条回答
  • 2021-02-06 14:34

    You can specify the whole day by doing a range, like so:

    WHERE bk_date >= TO_DATE('2012-03-18', 'YYYY-MM-DD')
    AND bk_date <  TO_DATE('2012-03-19', 'YYYY-MM-DD')
    

    More simply you can use TRUNC:

    WHERE TRUNC(bk_date) = TO_DATE('2012-03-18', 'YYYY-MM-DD')
    

    TRUNC without parameter removes hours, minutes and seconds from a DATE.

    0 讨论(0)
  • 2021-02-06 14:36

    Answer provided by Nicholas Krasnov

    SELECT *
    FROM BOOKING_SESSION
    WHERE TO_CHAR(T_SESSION_DATETIME, 'DD-MM-YYYY') ='20-03-2012';
    
    0 讨论(0)
提交回复
热议问题