Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem comparing date values

 
pourush rohila
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am trying to compare current date value with database value when i print d,dt,dt1 it gives same result but when compare dt, dt1 then it goes to false part of the if condition
please provide siolution
below is the code i use


i am using access database and field of the database is of date type
 
Abhishekshri Shrivastava
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pourush,

Can you check the value you are getting from select query. Try to print the value of dt1 and check what value you are getting here.Do also check the format.
Your code should work.


even you can also compare the dates in following way:-->

 
Rob Spoor
Sheriff
Pie
Posts: 20751
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.sql.Date does not override the equals method. That means that it uses the implementation of java.util.Date. That will only return true if the other object is another Date with the exact same timestamp, in milliseconds. I really doubt that you have such values in the database.

To compare on days, please SearchFirst. Our Java in General forum has seen that question many times already.
 
pourush rohila
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abhishekshri Shrivastava wrote:pourush,

Can you check the value you are getting from select query. Try to print the value of dt1 and check what value you are getting here.Do also check the format.
Your code should work.


even you can also compare the dates in following way:-->





thank you for reply abhishek but this one is also not working but i am converting bot dt and dt1 in string and compare it gives correct answer.

 
pourush rohila
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:java.sql.Date does not override the equals method. That means that it uses the implementation of java.util.Date. That will only return true if the other object is another Date with the exact same timestamp, in milliseconds. I really doubt that you have such values in the database.

To compare on days, please SearchFirst. Our Java in General forum has seen that question many times already.



thank you rob for reply i am trying with timestamp also but it gives correct answer when i convert in String.
 
pourush rohila
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
now i have a new problem i want to check only current date and month from database to current system date and month.
for example current date is 6-5-2012 (6th may 2012) and in database i store 6-5-2010(6th may 2012) so i want to check only 6-5(6th may) from both dates.
 
Rob Spoor
Sheriff
Pie
Posts: 20751
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use java.util.Calendar to retrieve the month and day. You can create one, then set its time from any object that's an instance of java.util.Date or its sub classes.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic