This week's book / license giveaways are in the JDBC and Relational Databases and Java in General forums.
We're giving away four copies each of PostGIS in Action and Java Advanced Topics Training and have the authors on-line!
See this thread and this one 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

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: 10417

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