-->
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.  [ 9 posts ] 
Author Message
 Post subject: When using QBE, how can you search using a partial date?
PostPosted: Tue Feb 14, 2006 10:48 am 
Beginner
Beginner

Joined: Sun Jun 05, 2005 9:45 am
Posts: 27
When using Query By Example, how can I search on a part of a date?

For example: I have a Event object which has an event date. How can I find all objects with a given MM/DD? I appreciate your help.

Regards,

Joshua


Top
 Profile  
 
 Post subject: Re: When using QBE, how can you search using a partial date?
PostPosted: Tue Feb 14, 2006 12:37 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
gigabee wrote:
When using Query By Example, how can I search on a part of a date?

For example: I have a Event object which has an event date. How can I find all objects with a given MM/DD? I appreciate your help.

Regards,

Joshua


I doubt that you can if the field you are searching is a date field. You're "example" wouldn't be able to contain a valid date.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject: Exactly
PostPosted: Tue Feb 14, 2006 1:33 pm 
Beginner
Beginner

Joined: Sun Jun 05, 2005 9:45 am
Posts: 27
There has to be a way to search by a partial date. Granted the criteria is not usually MM/DD, I am sure people have needed to search by just the year.

Any ideas?

Regards,

Joshua


Top
 Profile  
 
 Post subject: Re: Exactly
PostPosted: Tue Feb 14, 2006 3:32 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
gigabee wrote:
There has to be a way to search by a partial date. Granted the criteria is not usually MM/DD, I am sure people have needed to search by just the year.

Any ideas?

Regards,

Joshua


Sure you can, just not with QBE. Critiria queries allow you do search by dates using > < = or between two ACTUAL dates.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject: ok
PostPosted: Tue Feb 14, 2006 8:59 pm 
Beginner
Beginner

Joined: Sun Jun 05, 2005 9:45 am
Posts: 27
Ok,

so if QBE is out, the partial date problem still exists. How would you do it?


Top
 Profile  
 
 Post subject: Re: ok
PostPosted: Tue Feb 14, 2006 9:19 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
gigabee wrote:
Ok,

so if QBE is out, the partial date problem still exists. How would you do it?



Using Criteria queries assuming you have a mapped object with a Date attribute named myDateAttribute.

For the between case, you simply construct from a startDate of 01/01/YYYY for what ever year you're dealing with and an endDate of 12/31/YYYY for the same year.

Code:
criteria.add(Restrictions.between("mydateAttribute", startDate, endDate))

criteria.add(Restrictions.ge("mydateAttribute", startDate))

criteria.add(Restrictions.lt("mydateAttribute", endDate))

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject: Re: ok
PostPosted: Wed Mar 15, 2006 9:24 am 
Newbie

Joined: Wed Mar 15, 2006 9:15 am
Posts: 2
pksiv wrote:

For the between case, you simply construct from a startDate of 01/01/YYYY for what ever year you're dealing with and an endDate of 12/31/YYYY for the same year.

Code:
criteria.add(Restrictions.between("mydateAttribute", startDate, endDate))

criteria.add(Restrictions.ge("mydateAttribute", startDate))

criteria.add(Restrictions.lt("mydateAttribute", endDate))


OK, but what if the criteria is about the month or the day? For example... "give me all the products bought in June (no matter the day or the year)"

I don't know how to do it... maybe mixing Criteria with plain SQL? But it doesn't seem very elegant... :(


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 15, 2006 12:44 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
if your database support like for date you can do it with simple LIKE condition (and string parameter in condition).
(oracle support like for date and number, for example)


Top
 Profile  
 
 Post subject: Easy comparision - integration of Java and Hibernate
PostPosted: Thu Jan 18, 2007 5:07 am 
Newbie

Joined: Thu Jan 18, 2007 4:58 am
Posts: 1
Location: Muenchen, Germany
Hi,

do get entries out of a table on the DB, where the date is in one month, you pursue the following:

Code:
Calendar start_june= new GregorianCalendar();
Calendar end_june= new GregorianCalendar();
// Set the start and end dates to first of June and 30th

int year= 2007;   // e.g.

start_june.set(year, Calendar.JUNE,  1);
end_june.set(year, Calendar.JUNE, 30);

Criteria criteria = getSession().createCriteria(MyDomainTable.class);

...

criteria= criteria.add(Restrictions.ge("birthday", start_june.getTime()));
criteria= criteria.add(Restrictions.le("birthday", end_june.getTime()));



So easy :)

_________________
Per aspera ad astra!


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