-->
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: find number of days in hql query
PostPosted: Wed May 05, 2010 3:04 pm 
Newbie

Joined: Sun Jun 14, 2009 6:20 am
Posts: 7
Hi!
I use hql in named query. I'm interested to select records from the database between a birth_date and 30 days earlier. How do I do?
In mysql birt_date column it's timestamp type. Ex "2009-12-31 12:01:33".
Generally speaking, how can I find out the number of days between two dates by using HQL in named query?


Top
 Profile  
 
 Post subject: Re: find number of days in hql query
PostPosted: Thu May 06, 2010 1:38 pm 
Newbie

Joined: Sun Jun 14, 2009 6:20 am
Posts: 7
Nobody can suggest an solution?
I still have a question regarding. How can I explain these results?
Code:
select cm.datain+60, cm.datain from Clientmas cm where cm.id=207
'Wed Mar 10 20:48:15 EET 2010';'Wed Mar 10 20:47:15 EET 2010' ---> 60 seconds difference

select cm.dataintroducere+600, cm.dataintroducere from Clientmas cm where cm.id=207
'Wed Mar 10 20:53:15 EET 2010';'Wed Mar 10 20:47:15 EET 2010' ---> 360 seconds difference

select cm.dataintroducere+6000, cm.dataintroducere from Clientmas cm where cm.id=207
'Wed Mar 10 21:07:15 EET 2010';'Wed Mar 10 20:47:15 EET 2010' ---> 1200 seconds difference

What happens when add an integer value to a variable of Date type.


Top
 Profile  
 
 Post subject: Re: find number of days in hql query
PostPosted: Thu May 06, 2010 2:54 pm 
Newbie

Joined: Sun Jun 14, 2009 6:20 am
Posts: 7
I found an simple solutions. HQL understand MySQL functions so to extract records older than 60 days i use that:
Code:
from Clientmas cm where current_date > adddate(cm.datain,60)

Anyway, is strange that these sequence not work:
Code:
from Clientmas cm where current_date > ADDDATE(cm.datain,60)
java.rmi.NoSuchObjectException: no such object in table

Looks like MySQL functions are interpreted somehow case sensitive.


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.