-->
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.  [ 4 posts ] 
Author Message
 Post subject: hql query help - date expression
PostPosted: Tue May 08, 2007 3:38 pm 
Newbie

Joined: Mon Mar 27, 2006 7:46 pm
Posts: 17
I need to write a query that is something like this:
select data from Object data where data.createDate + 30days < current_date()

Is there a way to create an expression like this (data.createDate + 30days) with hql?

thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 08, 2007 5:14 pm 
Newbie

Joined: Thu Jan 04, 2007 1:36 pm
Posts: 16
You should be able to execute it using the following:
select c.* from <Class> c where (c.createDate + 30) < current_date()
or you can simply use the DB specific date function like addDays() or something in that terms in your hql.. ex:
select c.* from <Class> c where addDays(c.createDate, 30) < current_date()
Hope that helps.
- Arun


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 11, 2007 7:38 pm 
Newbie

Joined: Mon Mar 27, 2006 7:46 pm
Posts: 17
arun231 wrote:
You should be able to execute it using the following:
select c.* from <Class> c where (c.createDate + 30) < current_date()



I tried this but it doesn't work. I want a way to do this that is database independent. BUt it seems like hibernate doesn't have any built in date functions to accomodate


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 13, 2007 6:36 pm 
Newbie

Joined: Sat Jan 20, 2007 3:16 pm
Posts: 9
I was looking for something along these lines, Would this work for you?

DateTime dt = DateTime.Today.addDays(-30);
IQuery qry = session.CreateQuery("select data from object where data.CreateDate < :date");
qry.SetDateTime(dt);
IList list = qry.List();

Murthy


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.