Two Laptop Bag
The moose likes JDBC and the fly likes SQl date conversion to java.util.Date object Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "SQl date conversion to java.util.Date object" Watch "SQl date conversion to java.util.Date object" New topic
Author

SQl date conversion to java.util.Date object

Poonam Kadu
Ranch Hand

Joined: Jul 21, 2006
Posts: 49
Hello friends,
How do I convert a date (mm/dd/yyyy)from SQl dbase to java.util.Date or java.sql.Date and then compare it with the current date retrieved through jaav.util.Date ?

cheers,
Poonam
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 26173
    
  66

Poonam,
You can get the date from the database as a java.sql.Date through rs.getDate() if you just need the date. [You would use rs.getTime() or rs.getTimeStamp() if you needed the time too.]

You can get the current system date as new java.util.Date(). Since java.sql.Date is a subclass of java.util.Date, you can compare the values using date1.compareTo(date2).


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: SQl date conversion to java.util.Date object
 
Similar Threads
Date and Datetime creation from a String.
HELP:Can "Date" in java compare with "Date" in Foxpro?
HELP:Can "Date" in java compare with "Date" in Foxpro?
How toconvert a String into date Object
ava.util.date and java.sql.date