It's not a secret anymore!
The moose likes JDBC and Relational Databases 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 Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "convert timestamp to date" Watch "convert timestamp to date" New topic

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

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:
subject: convert timestamp to date
It's not a secret anymore!