This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Comparing dates in hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Comparing dates in hibernate" Watch "Comparing dates in hibernate" New topic

Comparing dates in hibernate

Bob Green
Ranch Hand

Joined: Feb 29, 2004
Posts: 93
Here's my code:

This is not working because
dob.getTime() returns "Wed Apr 01 12:00:00 MST 1970"
Person.DOB returns "1970-03-01"

How do I make it to work?

Any help is greatly appreciated!


[ Edited to use code tags - Paul Sturrock ]
[ November 20, 2006: Message edited by: Paul Sturrock ]
Greg Hemlock

Joined: Nov 17, 2006
Posts: 1
Calendar.MONTH is zero based. dob.set(Calendar.MONTH, 2) should get you closer.
Jaikiran Pai

Joined: Jul 20, 2005
Posts: 9930

Better still, use:

[My Blog] [JavaRanch Journal]
sandy comp

Joined: Aug 11, 2001
Posts: 10
It seems Person.DOB returns string. You can format date to string and then compare. This happnes because if we say resultset.getString("DOB") where "DOB" is date column.

Design and programming are human activities; forget that and all is lost.
I agree. Here's the link:
subject: Comparing dates in hibernate
Similar Threads
Date 01/01/1970 returning non-zero value for time
Calendar() / Date() bug ???
hibernate problem.
converting sqldates?
Dynamic EJB QL