aspose file tools*
The moose likes JDBC and the fly likes convert timestamp to date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "convert timestamp to date" Watch "convert timestamp to date" New topic
Author

convert timestamp to date

Anthony Smith
Ranch Hand

Joined: Sep 10, 2001
Posts: 285
How do I convert a java.sql.Timestamp to java.sql.Date? I thought I could just cast the (java.sql.Date)timestamp_var but that does nto work.
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
Both of the classes (java.sql.Date and java.sql.Timestamp) subclass java.util.Date, so as "siblings" you can not cast instances of one to instances of another. However you'll notice that both of them inherit [or override] the "getTime()" method which returns a value of type "long". Both of them also have a constructor that takes a value of type "long".
So you can do the following:
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Moving this to the JDBC forum...


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: convert timestamp to date
 
Similar Threads
java.sql.Date and DateFormat
java.sql.date to string
how to generate sql date
convert timestamp to date
Problems setting sql Date in prepared statement