-->
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: Problem with dates comparing in HQL query
PostPosted: Tue Dec 20, 2005 5:04 am 
Newbie

Joined: Tue Dec 20, 2005 4:42 am
Posts: 2
Hi!
I just started to study hibernate, so possibly my question rather silly.

I have:
(it's Date.toSring() output)
start date: Sun Dec 19 00:00:00 MSK 2005
end date: Mon Dec 19 23:59:59 MSK 2005

Query String:

select e.body, e.date, e.number from MessageEntry e
where e.date <= :endDate AND e.date >= :startDate

This query with dates does not match entries with date
2005-12-19 19:46:43.0


If I use this dates
start date: Sun Dec 19 00:00:00 MSK 2005
end date: Mon Dec 20 23:59:59 MSK 2005

then it matches messages with date
2005-12-19 19:46:43.0


Can anybody explain, why I can't get messages in first case?
Where possible problem?

Maybe .hbm.xml incorrect, and need to change something?
<property name="date" column="message_date" not-null = "true" type="timestamp" />
(in DB table field type is timestamp)

Thanks.



Hibernate version: 3.0


Top
 Profile  
 
 Post subject: Re: Problem with dates comparing in HQL query
PostPosted: Tue Dec 20, 2005 5:23 am 
Newbie

Joined: Tue Dec 20, 2005 4:42 am
Posts: 2
and another question:

Is it posible to cut off "time part" of timestamp. Some SQL-like function?

For example 2005-12-19 19:46:43.0 -> 2005-12-19 00:00:00.0

This may help me with current request and for future report queries, where I'll need to use
GROUP BY statement to get messages count during days.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 20, 2005 6:27 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
date sq type (except with in oracle) haven't time part.
if you want time then use Timestamp
hibernate work correct because it is sql standard


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.