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: Adv. querying for dates
PostPosted: Tue Jun 27, 2006 6:57 am 
Newbie

Joined: Tue Jun 27, 2006 6:48 am
Posts: 1
Hi there.

I'll skip right to the problem.
In my database I have a set of UserBeans in my database, all which has a born-date field. From this I want to get all of the users that have their birthday on a given date.

Any clue upon how to do this with HQL or Criterias?

I can easily check their age, but I don't know how to ignore the year when doing HQL or Criterias.

In advance thanks..


Kenneth


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 27, 2006 8:08 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
HQL has the day() and month() functions (see ref docs section 14.9, "Expressions", for a more complete list.

Using criteria, you'd probably have to use sqlRestriction with the datepart() SQL funciton (or whatever equivalent function your DBMS offers).

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 28, 2006 9:59 am 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
With oracle the following code works for me.

Code:
String dateValue = "28";
String sql = "to_char(trunc( my_date_column ), 'dd') = " + dateValue;
Criteria c = session.createCriteria( MyPersistent.class );
c.add( Restrictions.sqlRestriction( sql ) );
List objects = c.list();


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.