tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alistair Hopkins" <>
Subject RE: Dates in Java
Date Fri, 06 Apr 2001 12:38:46 GMT
try "select myDate - 7 from myTable;" in your SQL statement for a quick fix
(works on postgres, don't know about msql)

-----Original Message-----
From: Michael Wentzel []
Sent: Friday, April 06, 2001 12:58 PM
To: ''
Subject: RE: Dates in Java

I have a simple question about the Date object (or similar object)

I have a mySQL table with a DATETIME cell. I want to get the date from this

(formatted like so: e.g.  2001-03-23 13:04:59)

 and retrieve the date that is exactly 7 days earlier than the retrieved

What is the easiest way to do this? I noticed a lot of method deprecations
in the specs and I am having trouble using the Date object.
For example, cannot resolve symbol
symbol  : constructor Date  ()
location: class java.sql.Date
                Date d = new Date();
1 error


First, in regards to displaying your date use the java.text.DateFormat
class(note DateFormat
is abstract so of course you'll want to use one of the 'implementation'
classes).  Since
java.sql.Date extends java.util.Date you can of course use the
java.text.DateFormat classes
to format a java.sql.Date.

Secondly, the problem you are having using java.sql.Date could be if you are
importing java.util.*.  This will import java.util.Date in addition to
Therefore, when you code Date d = new Date() the compiler doesn't know which
to use.  One solution to to not import anything using splay(*).  This is the
way we
do it.  You import block may get a little large but it also makes it easier
for other
developers to figure out where to look for source.  Another is to code it as
java.sql.Date d = new java.sql.Date();

Michael Wentzel
Software Developer
Software As We Think -

View raw message