aspose file tools
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 The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "comparing dates in hibernate" Watch "comparing dates in hibernate" New topic

comparing dates in hibernate

shah rah
Ranch Hand

Joined: Jan 04, 2007
Posts: 124
this is how my date value is inside database (sqlServer)
2007-05-04 11:39:25.553, 2007-05-03 13:37:37.150

the user can enter date in mm/dd/yyyy(dfInputdatefmt) format. so I convert it to yyyy-MM-dd hh:mm:ss:SSS(dfOutputdatefmt) like this

Then I use

if I provide dateTo as 05/04/2007 and datFrom as 01/01/2007 is missing all the 05/04/2007 records.

Whats wrong? Pls help me
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17260

Think of dates as having time stamps. Do if you just put a Day, Month, Year, there is still a time element in there, like Midnight. So anything done in the day, like 4PM, happens before Midnight. That is why. If you want to compare at the day level, you need to convert both sides to just the Day, Month, Year and take out the time portion.


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
I agree. Here's the link:
subject: comparing dates in hibernate