Two Laptop Bag
The moose likes JDBC and Relational Databases and the fly likes SQl date conversion to java.util.Date object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
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
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 32501
    
214

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).


[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SQl date conversion to java.util.Date object
 
It's not a secret anymore!