Using HQL to query on a date while ignoring the time on Oracle

后端 未结 4 1093
暖寄归人
暖寄归人 2020-12-06 04:59

I have a table (in Oracle 9 and up) where I need to find all entries for a given day using Hibernate. The entries have timestamps (with data type \'date\'). Some of the entr

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-06 06:03

    You could put two constraints into your HQL, one that specifies greater than or equal to the start of the date you are searching on, and one that specifies less than the next day.

    i.e.

    table.date >=11.06.2009 AND table.date < 11.07.2009
    

    HQL (as well as SQL) also allows for:

    table.date between 11.06.2009 AND 11.07.2009
    

    Keep in mind between is always inclusive, meaning it's both >= and <= respectively.
    More details on between here: http://www.coding-dude.com/wp/java/hibernate-java/hibernate-hql-between-expression/

提交回复
热议问题