Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

convert timestamp to date

 
Anthony Smith
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the JDBC forum...
[ October 03, 2003: Message edited by: Dirk Schreckmann ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic