• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem comparing date values

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:-->

 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic