wood burning stoves 2.0*
The moose likes JDBC and the fly likes Date is there.  Timestamp is not. 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 » Databases » JDBC
Bookmark "Date is there.  Timestamp is not. " Watch "Date is there.  Timestamp is not. " New topic

Date is there. Timestamp is not.

Chris Montgomery
Ranch Hand

Joined: Jan 14, 2004
Posts: 141
I need to do get the difference in MINUTES between now (Calendar.getInstance()) and a datetime value from MySQL.

Java is telling me Calendar.getInstance() is:
Fri Jul 24 19:15:03 CDT 2009

In my table, the value stored is:
2009-07-24 18:59:45

After retrieving the data from my database, Java stored the datetime value as this:
Fri Jul 24 00:00:00 CDT 2009

As a result, I can't get the correct difference in minutes.

Here's how I'm loading up my domain object:




Rob Spoor

Joined: Oct 27, 2005
Posts: 19651

Use rs.getTimestamp(). rs.getDate() removes time information, rs.getTime() removes date information, rs.getTimestamp preserves both.

How To Ask Questions How To Answer Questions
I agree. Here's the link: http://aspose.com/file-tools
subject: Date is there. Timestamp is not.
Similar Threads
add 10 days to currentDate in java.util.Date or cast to Calendar?
Retreiving the current data from the database
A strange compile classpathing issue Im having
Error passing in a date object
Strange problem in date calculation (IS IT BUG!!!)