开发者

Search Oracle date type column with hibernate, search by everything in that day - ignore the time

batch create 开发者_如何学Cdate

table column type is

BATCH_CREATED_DATE  DATE            NOT NULL

With the data in that date column being similar to this '2010-05-13 14:56:36.0'

now I want to search for all items within the 24 hours of 2010-05-13, currently my call only returns all items with date "2010-05-13 14:56:36.0" exactly.

What would my HQL statement look like to hand this kind of scenario?


Depending on the parameters you're going to pass, I can think of several solutions:

  • With '2010-05-13 00:00:00.0' and '2010-05-13 23:59:59.9':

    from MyEntity e where e.date between :startDate and :endDate 
    
  • With '2010-05-13 00:00:00.0' and '2010-05-14 00:00:00.0':

    from MyEntity e where :startDate <= e.date and e.date < :endDate
    
  • With '2010-05-13 XX:XX:XX.X':

    from MyEntity e where year(e.date)  = year(:aDate) 
                      and month(e.date) = month(:aDate)
                      and day(e.date)   = day(:aDate) 
    


This could be useful. Using HQL to query on a date while ignoring the time on Oracle

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜