• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MS SQL server datetime and Java Date comparision problem

 
Fahed Siddiqui
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello I have date time problem in Hibernate , in hibernate mapping i have provided the type "timestamp" , In pesistent class I have a java.util.Date type varialbe in which i m saving current date time, in MS sql server table i have datetime type column to persist this variable.

following is the date time before storing and after loading from database :the problem is that
sometimes it returns true indicating that the date is same ,but someimes it gives false :
It should be always true while i compare both objects that is before persistence and after loading from the data base the persisted value for tha object:
i think this problem iss not bcoz of hibernae , it is MS sql server datetime and java Date calss type problem........plz eply me as soon as poosible , thanks in advance!

before storing Time obj2.getDate() = Wed Jun 23 10:21:56 GMT+05:00 2004
loading from database Time obj1.getDate()= 2004-06-23 10:21:56.093
Obj1.getDate().equals(obj2.getDate()) = true


before storing Time obj2.getDate()= Wed Jun 23 10:23:22 GMT+05:00 2004
loading from database Time obj1.getDate() = 2004-06-23 10:23:22.917
Obj1.getDate().equals(obj2.getDate()) time = false

before storing Time obj2.getDate() = Wed Jun 23 10:26:07 GMT+05:00 2004
loading from database Time obj1.getDate() = 2004-06-23 10:26:07.023
Obj1.getDate().equals(obj2.getDate()) Time = false

before storing Time obj2.getDate() = Wed Jun 23 10:27:18 GMT+05:00 2004
loading from database Time obj1.getDate() = 2004-06-23 10:27:18.497
Obj1.getDate().equals(obj2.getDate()) Time = true


before storing Time obj2.getDate() = Wed Jun 23 10:29:36 GMT+05:00 2004
loading from database Time obj1.getDate() = 2004-06-23 10:29:36.547
Obj1.getDate().equals(obj2.getDate()) Time = false
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"famous creature",

Please take a moment to read our naming policy and go here to edit your displayed name into something compliant with the said policy.

Thank you.
 
Jez Nicholson
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
....or just repost your question with a different word ordering in the title ;-)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic