Date Compare in HQL without timestamp

后端 未结 2 1945
一向
一向 2021-02-14 02:58

I have to compare two dates in hibernate hql query. I am using java.util.Date in my java bean and using timestamp as datatype in mysql database.

select t from Ta         


        
2条回答
  •  梦谈多话
    2021-02-14 03:12

    See the Hibernate documentations for available date functions

    http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/queryhql.html

    In section 14.10 notice this line

    second(...), minute(...), hour(...), day(...), month(...), and year(...)
    

    So this should work

    ... where year(t.endDate) > year(t.startDate) 
        and month(t.endDate) > month(t.startDate)
        and day(t.endDate) > day(t.startDate)
    

    The solution reported as satisfying the question is

     ... where DATE(t.endDate) > (t.startDate)
    

提交回复
热议问题