-->
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.  [ 2 posts ] 
Author Message
 Post subject: difference (in days) between two dates...
PostPosted: Mon Nov 26, 2007 12:12 pm 
Newbie

Joined: Thu Aug 30, 2007 9:14 am
Posts: 6
How can i write this very simple mysql SQL in hibernate HQL??

SELECT DATEDIFF(now(), my_date) FROM my_table

I don't find any useful function.
Can you help? thank you.


Top
 Profile  
 
 Post subject: Had the same problem - here is my solution
PostPosted: Wed Dec 12, 2007 12:40 pm 
Newbie

Joined: Tue Jan 30, 2007 11:28 am
Posts: 1
Hello dupa,

I had the same requirement last week and I could not find a way to do it using hibernate HQL. However my solution was to create a query object and use the createSQLQuery method to create the raw MySQL query.

Eg:

Code:
Query sqlQuery = session.createSQLQuery("SELECT DATEDIFF(now(), my_date) FROM my_table");

and then

return sqlQuery.list();


I hope it helps, I know this type of queries is not portable to other DBs. If anybody knows a better solution I will be happy to here it.


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