-->
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.  [ 7 posts ] 
Author Message
 Post subject: How to find Date difference using HQL
PostPosted: Fri Sep 18, 2009 1:59 pm 
Newbie

Joined: Fri Sep 18, 2009 1:50 pm
Posts: 6
Hi,

I have a requirement to check the date differece between for two dates retrieved from the database and check for a condition. something like given below

from classA a where ((a.expDate - a.valDate)/365) >= 4 and
((a.expDate - a.valDate)/365) <= 8


Will be greatful for the response.

Thanks,
-Sreeni


Top
 Profile  
 
 Post subject: Re: How to find Date difference using HQL
PostPosted: Fri Sep 18, 2009 6:59 pm 
Senior
Senior

Joined: Mon Jul 07, 2008 4:35 pm
Posts: 141
Location: Berlin
Hi smannur,

according to the HQL docs (see http://docs.jboss.org/hibernate/stable/core/reference/en/html/queryhql.html#queryhql-expressions) HQL supports a rich set of mathematical operators. At least the comparison operators work with date types. I don't know about the others.

You should probably make sure what the exact results of your intermediate calculation steps are to find out where there is a problem. Comparing the result of a division with an integer might be an issue.

That were just some ideas I had on your problem - I didn't check anything.

CU
Froestel

_________________
Have you tried turning it off and on again? [Roy]


Top
 Profile  
 
 Post subject: Re: How to find Date difference using HQL
PostPosted: Sat Sep 19, 2009 3:32 pm 
Newbie

Joined: Fri Sep 18, 2009 1:50 pm
Posts: 6
Froestel,

Thanks for ur response. I want some function or claculation supported by hql to find the diff between two dates(in # of days).

The database we are using is oracle10g

Thanks,
-Sreeni


Top
 Profile  
 
 Post subject: Re: How to find Date difference using HQL
PostPosted: Thu Sep 24, 2009 12:00 am 
Newbie

Joined: Fri Sep 18, 2009 1:50 pm
Posts: 6
Can someone pls respond to me on this query???


Top
 Profile  
 
 Post subject: Re: How to find Date difference using HQL
PostPosted: Thu Sep 24, 2009 6:05 pm 
Newbie

Joined: Mon Sep 14, 2009 2:22 pm
Posts: 5
Hi Sreeni,

Hope you have got answer for your question, If not please try this query to calculate difference in days,

Use following query to calculate the difference in days and then divide this value with 365

Code:
select trunc (to_date('2005/04/18 11:05:00','YYYY/MM/DD HH24:MI:SS')-to_date('2005/04/15 10:15:32','YYYY/MM/DD HH24:MI:SS')) as days from dual;


to_date and trunc are valid functions in HQL. So this query might work for you in HQL to calculate number of days.

Hope this info is useful

Shruthi


Top
 Profile  
 
 Post subject: Re: How to find Date difference using HQL
PostPosted: Thu Sep 24, 2009 6:09 pm 
Newbie

Joined: Fri Sep 18, 2009 1:50 pm
Posts: 6
Thanks Shruthi,

I will check your sugessions!!

Thanks,
-Sreeni


Top
 Profile  
 
 Post subject: Re: How to find Date difference using HQL
PostPosted: Fri Sep 25, 2009 7:05 pm 
Newbie

Joined: Fri Sep 18, 2009 1:50 pm
Posts: 6
Thanks a lot Shruthi. It is perfectly working fine.

If you can, pls help me on this hql query.

viewtopic.php?f=1&t=999881

Thanks,
-Sreeni


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