-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Search using dates
PostPosted: Mon Aug 22, 2011 7:41 am 
Newbie

Joined: Mon Aug 22, 2011 7:38 am
Posts: 2
My table has date fields with type as datetime or timestamp. I would like to fetch the records based on the values of these fields.
That is, let's say, I want all records inserted or updated today. What would be the HQL for the same?

I don't want to use Criteria API but only HQL.

Thanks.


Top
 Profile  
 
 Post subject: Re: Search using dates
PostPosted: Mon Aug 22, 2011 9:43 am 
Newbie

Joined: Mon Aug 22, 2011 8:46 am
Posts: 1
.


Top
 Profile  
 
 Post subject: Re: Search using dates
PostPosted: Tue Aug 23, 2011 3:40 am 
Newbie

Joined: Mon Aug 22, 2011 7:38 am
Posts: 2
Following HQL serves the purpose:

From someTable where (day(createdOn) = day(current_date())) and (month(createdOn) = month(current_date())) and (year(createdOn) = year(current_date()))

Assumption: "createdOn" is a date/time field.

Any better solution??


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.