wood burning stoves 2.0*
The moose likes Beginning Java 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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
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...
[ October 03, 2003: Message edited by: Dirk Schreckmann ]

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
wood burning stoves
 
subject: convert timestamp to date
 
Similar Threads
java.sql.date to string
Problems setting sql Date in prepared statement
convert timestamp to date
java.sql.Date and DateFormat
how to generate sql date