File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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: 10441

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
It's not a secret anymore!