permaculture playing cards*
The moose likes JDBC 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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
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: 30138
    
150

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://aspose.com/file-tools
 
subject: SQl date conversion to java.util.Date object
 
Similar Threads
Date and Datetime creation from a String.
How toconvert a String into date Object
ava.util.date and java.sql.date
HELP:Can "Date" in java compare with "Date" in Foxpro?
HELP:Can "Date" in java compare with "Date" in Foxpro?