-->
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.  [ 4 posts ] 
Author Message
 Post subject: Date comparison with literals
PostPosted: Wed Jun 23, 2004 3:09 am 
Beginner
Beginner

Joined: Sun Jun 20, 2004 11:39 pm
Posts: 24
Hi there,
I have searched the forum and checked the documentation but I cant seem to find how to compare dates with literals in hql.


my database is mysql latest version
my hbm.xml file stores the type as date

select sbm from User as u inner join u.smsBoxMessages as sbm where u.id=1 and sbm.receipientMobileNumber like "%%" and sbm.date >= "2003-01-01" and sbm.date<= "2004-01-01" and sbm.message like "%%"

The date stored in mysql is "2004-06-23"

the hql compiles correctly and able to retrieve the data i want when the date sbm.date="2004-06-23" which is the same as the date in the database but it doesnt work when i try "2003-01-01" in the above hql


i am trying to get rows that are between certain dates and i want to be able to specify those dates in the hql

can anyone give me any pointers? or am i comparing the dates wrongly? if so can anyone give me an example or how i can compare dates with a custom value in hql?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 23, 2004 4:15 am 
Beginner
Beginner

Joined: Thu Jan 08, 2004 4:40 am
Posts: 48
Location: Bangkok, Thailand
Dear Dude
Why don't you use BETWEEN AND instead of >= and =<, I think this might help you. Because I'm using it.
Cheers

_________________
<name>arin</name>
<at>netplus software</at>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 23, 2004 6:01 am 
Beginner
Beginner

Joined: Sun Jun 20, 2004 11:39 pm
Posts: 24
you mean like this?

sbm.date between "2001-01-01" and "2002-01-01"

would the "between and" be inclusive of 2001-01-01 and 2002-01-01 ?

or is there a way to specify inclusive or exclusive?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 23, 2004 6:41 am 
Beginner
Beginner

Joined: Thu Jan 08, 2004 4:40 am
Posts: 48
Location: Bangkok, Thailand
sbm.date between "2001-01-01" and "2002-01-01"
The result set from BETWEEN .... AND ..... will include "2001-01-01" and "2002-01-01". I try to map from

sbm.date >= "2003-01-01" and sbm.date<= "2004-01-01"

I think >= and <= mean inclusive start and end date into result

Cheers

_________________
<name>arin</name>
<at>netplus software</at>


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