You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Michael Wentzel <Mi...@aswethink.com> on 2001/04/06 13:57:46 UTC

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
cell
 
(formatted like so: e.g.  2001-03-23 13:04:59)
 
 and retrieve the date that is exactly 7 days earlier than the retrieved
date.
 
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, 
DateTest.java:20: 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
java.sql.Date.
Therefore, when you code Date d = new Date() the compiler doesn't know which
classdef
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 - http://www.aswethink.com

Re: Dates in Java

Posted by Alvin Yap <al...@sympatico.ca>.
I think you need a java.sql.Timestamp type as compared to java.util.Date type
To create new timestamp or

long time = System.currentTimeMillis();
Timestamp currentTime = new Timestamp( time );
....

...
This object will hold the date and time.  If you want to format the time
differently use Calendar and Formatter to achieve this.

Alvin


Jeff Kilbride wrote:

> There's also something to be said for using a little tact. "You might get
> more help posting your question on a general Java forum" -- and then
> pointing the way -- is better than using three question marks and implying
> that the other person's question is "so simple". Responses like this scare
> new programmers off the lists.
>
> I remember my first post...
>
> --jeff
>
> ----- Original Message -----
> From: "Milt Epstein" <me...@uiuc.edu>
> To: <to...@jakarta.apache.org>
> Sent: Friday, April 06, 2001 7:05 AM
> Subject: Re: Dates in Java
>
> > On Fri, 6 Apr 2001, Martin Mauri wrote:
> >
> > > Hey...don't be so rude, let the boys work their problems out...
> >
> > There is something to be said for keeping a list on-topic, and people
> > asking questions on appropriate forums.
> >
> >
> > > > Are we in the tomcat-user forum ???
> > > > I don't see the relationship between a so simple constructor problem
> > > > (which Javadoc solve quiet easily ...) and Tomcat ...
> > > >
> > > >
> > > > Alistair Hopkins a écrit :
> > > > >
> > > > > 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 [mailto:Michael.Wentzel@aswethink.com]
> > > > > Sent: Friday, April 06, 2001 12:58 PM
> > > > > To: 'tomcat-user@jakarta.apache.org'
> > > > > 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
> > > > > cell
> > > > >
> > > > > (formatted like so: e.g.  2001-03-23 13:04:59)
> > > > >
> > > > >  and retrieve the date that is exactly 7 days earlier than the
> retrieved
> > > > > date.
> > > > >
> > > > > 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,
> > > > > DateTest.java:20: 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
> > > > > java.sql.Date.
> > > > > Therefore, when you code Date d = new Date() the compiler doesn't
> know
> > > which
> > > > > classdef
> > > > > 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 - http://www.aswethink.com
> > > >
> > > > --
> > > > Cordialement,
> > > >
> > > >
> > > > Stéphane BAUDET
> > > >
> > > > _________________________________________________________
> > > > GL Trade
> > > > 48, rue Notre Dame des Victoires - 75002 Paris
> > > > Tel : 01 53 40 43 12 (interne 1312)
> > > > Fax : 01 53 40 01 40
> > > > Email : sbaudet@gltrade.fr
> > > > _________________________________________________________
> > >
> >
> > Milt Epstein
> > Research Programmer
> > Software/Systems Development Group
> > Computing and Communications Services Office (CCSO)
> > University of Illinois at Urbana-Champaign (UIUC)
> > mepstein@uiuc.edu
> >


Re: Dates in Java

Posted by Martin Mauri <mm...@profesi.com.ar>.
Milt!

Stop it, you're posting an out topic message! We're not discussing here
about policies, we're talkig about Tomcat!

:)

regards.



> On Fri, 6 Apr 2001, Jeff Kilbride wrote:
>
> > There's also something to be said for using a little tact. "You
> > might get more help posting your question on a general Java forum"
> > -- and then pointing the way -- is better than using three question
> > marks and implying that the other person's question is "so
> > simple". Responses like this scare new programmers off the lists.
> [ ... ]
>
> True, but I don't see anything so rude about what the person wrote,
> despite the use of multiple question marks and the "so simple" -- I've
> seen a lot worse (hell, I've responded a lot worse myself :-).  And I
> could see how it can be a little annoying after a whole bunch of such
> posts.  Also remember that it's quite possible that English is not his
> native language.
>
> Anyway, this list has seemed reasonable on-topic (as well as useful
> and friendly) since I joined, so this probably isn't something to be
> concerned about (on either side).
>
>
> > ----- Original Message -----
> > From: "Milt Epstein" <me...@uiuc.edu>
> > To: <to...@jakarta.apache.org>
> > Sent: Friday, April 06, 2001 7:05 AM
> > Subject: Re: Dates in Java
> >
> >
> > > On Fri, 6 Apr 2001, Martin Mauri wrote:
> > >
> > > > Hey...don't be so rude, let the boys work their problems out...
> > >
> > > There is something to be said for keeping a list on-topic, and people
> > > asking questions on appropriate forums.
> > >
> > >
> > > > > Are we in the tomcat-user forum ???
> > > > > I don't see the relationship between a so simple constructor
problem
> > > > > (which Javadoc solve quiet easily ...) and Tomcat ...
> > > > >
> > > > >
> > > > > Alistair Hopkins a écrit :
> > > > > >
> > > > > > 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 [mailto:Michael.Wentzel@aswethink.com]
> > > > > > Sent: Friday, April 06, 2001 12:58 PM
> > > > > > To: 'tomcat-user@jakarta.apache.org'
> > > > > > 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
> > > > > > cell
> > > > > >
> > > > > > (formatted like so: e.g.  2001-03-23 13:04:59)
> > > > > >
> > > > > >  and retrieve the date that is exactly 7 days earlier than the
> > retrieved
> > > > > > date.
> > > > > >
> > > > > > 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,
> > > > > > DateTest.java:20: 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
> > > > > > java.sql.Date.
> > > > > > Therefore, when you code Date d = new Date() the compiler
doesn't
> > know
> > > > which
> > > > > > classdef
> > > > > > 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 - http://www.aswethink.com
> > > > >
> > > > > --
> > > > > Cordialement,
> > > > >
> > > > >
> > > > > Stéphane BAUDET
> > > > >
> > > > > _________________________________________________________
> > > > > GL Trade
> > > > > 48, rue Notre Dame des Victoires - 75002 Paris
> > > > > Tel : 01 53 40 43 12 (interne 1312)
> > > > > Fax : 01 53 40 01 40
> > > > > Email : sbaudet@gltrade.fr
> > > > > _________________________________________________________
> > > >
> > >
> > > Milt Epstein
> > > Research Programmer
> > > Software/Systems Development Group
> > > Computing and Communications Services Office (CCSO)
> > > University of Illinois at Urbana-Champaign (UIUC)
> > > mepstein@uiuc.edu
> > >
> >
>
> Milt Epstein
> Research Programmer
> Software/Systems Development Group
> Computing and Communications Services Office (CCSO)
> University of Illinois at Urbana-Champaign (UIUC)
> mepstein@uiuc.edu


Re: Dates in Java

Posted by Milt Epstein <me...@uiuc.edu>.
On Fri, 6 Apr 2001, Jeff Kilbride wrote:

> There's also something to be said for using a little tact. "You
> might get more help posting your question on a general Java forum"
> -- and then pointing the way -- is better than using three question
> marks and implying that the other person's question is "so
> simple". Responses like this scare new programmers off the lists.
[ ... ]

True, but I don't see anything so rude about what the person wrote,
despite the use of multiple question marks and the "so simple" -- I've
seen a lot worse (hell, I've responded a lot worse myself :-).  And I
could see how it can be a little annoying after a whole bunch of such
posts.  Also remember that it's quite possible that English is not his
native language.

Anyway, this list has seemed reasonable on-topic (as well as useful
and friendly) since I joined, so this probably isn't something to be
concerned about (on either side).


> ----- Original Message -----
> From: "Milt Epstein" <me...@uiuc.edu>
> To: <to...@jakarta.apache.org>
> Sent: Friday, April 06, 2001 7:05 AM
> Subject: Re: Dates in Java
> 
> 
> > On Fri, 6 Apr 2001, Martin Mauri wrote:
> >
> > > Hey...don't be so rude, let the boys work their problems out...
> >
> > There is something to be said for keeping a list on-topic, and people
> > asking questions on appropriate forums.
> >
> >
> > > > Are we in the tomcat-user forum ???
> > > > I don't see the relationship between a so simple constructor problem
> > > > (which Javadoc solve quiet easily ...) and Tomcat ...
> > > >
> > > >
> > > > Alistair Hopkins a �crit :
> > > > >
> > > > > 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 [mailto:Michael.Wentzel@aswethink.com]
> > > > > Sent: Friday, April 06, 2001 12:58 PM
> > > > > To: 'tomcat-user@jakarta.apache.org'
> > > > > 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
> > > > > cell
> > > > >
> > > > > (formatted like so: e.g.  2001-03-23 13:04:59)
> > > > >
> > > > >  and retrieve the date that is exactly 7 days earlier than the
> retrieved
> > > > > date.
> > > > >
> > > > > 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,
> > > > > DateTest.java:20: 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
> > > > > java.sql.Date.
> > > > > Therefore, when you code Date d = new Date() the compiler doesn't
> know
> > > which
> > > > > classdef
> > > > > 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 - http://www.aswethink.com
> > > >
> > > > --
> > > > Cordialement,
> > > >
> > > >
> > > > St�phane BAUDET
> > > >
> > > > _________________________________________________________
> > > > GL Trade
> > > > 48, rue Notre Dame des Victoires - 75002 Paris
> > > > Tel : 01 53 40 43 12 (interne 1312)
> > > > Fax : 01 53 40 01 40
> > > > Email : sbaudet@gltrade.fr
> > > > _________________________________________________________
> > >
> >
> > Milt Epstein
> > Research Programmer
> > Software/Systems Development Group
> > Computing and Communications Services Office (CCSO)
> > University of Illinois at Urbana-Champaign (UIUC)
> > mepstein@uiuc.edu
> >
> 

Milt Epstein
Research Programmer
Software/Systems Development Group
Computing and Communications Services Office (CCSO)
University of Illinois at Urbana-Champaign (UIUC)
mepstein@uiuc.edu


Re: Dates in Java

Posted by Jeff Kilbride <je...@kilbride.com>.
There's also something to be said for using a little tact. "You might get
more help posting your question on a general Java forum" -- and then
pointing the way -- is better than using three question marks and implying
that the other person's question is "so simple". Responses like this scare
new programmers off the lists.

I remember my first post...

--jeff

----- Original Message -----
From: "Milt Epstein" <me...@uiuc.edu>
To: <to...@jakarta.apache.org>
Sent: Friday, April 06, 2001 7:05 AM
Subject: Re: Dates in Java


> On Fri, 6 Apr 2001, Martin Mauri wrote:
>
> > Hey...don't be so rude, let the boys work their problems out...
>
> There is something to be said for keeping a list on-topic, and people
> asking questions on appropriate forums.
>
>
> > > Are we in the tomcat-user forum ???
> > > I don't see the relationship between a so simple constructor problem
> > > (which Javadoc solve quiet easily ...) and Tomcat ...
> > >
> > >
> > > Alistair Hopkins a écrit :
> > > >
> > > > 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 [mailto:Michael.Wentzel@aswethink.com]
> > > > Sent: Friday, April 06, 2001 12:58 PM
> > > > To: 'tomcat-user@jakarta.apache.org'
> > > > 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
> > > > cell
> > > >
> > > > (formatted like so: e.g.  2001-03-23 13:04:59)
> > > >
> > > >  and retrieve the date that is exactly 7 days earlier than the
retrieved
> > > > date.
> > > >
> > > > 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,
> > > > DateTest.java:20: 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
> > > > java.sql.Date.
> > > > Therefore, when you code Date d = new Date() the compiler doesn't
know
> > which
> > > > classdef
> > > > 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 - http://www.aswethink.com
> > >
> > > --
> > > Cordialement,
> > >
> > >
> > > Stéphane BAUDET
> > >
> > > _________________________________________________________
> > > GL Trade
> > > 48, rue Notre Dame des Victoires - 75002 Paris
> > > Tel : 01 53 40 43 12 (interne 1312)
> > > Fax : 01 53 40 01 40
> > > Email : sbaudet@gltrade.fr
> > > _________________________________________________________
> >
>
> Milt Epstein
> Research Programmer
> Software/Systems Development Group
> Computing and Communications Services Office (CCSO)
> University of Illinois at Urbana-Champaign (UIUC)
> mepstein@uiuc.edu
>


Re: Dates in Java

Posted by Milt Epstein <me...@uiuc.edu>.
On Fri, 6 Apr 2001, Martin Mauri wrote:

> Hey...don't be so rude, let the boys work their problems out...

There is something to be said for keeping a list on-topic, and people
asking questions on appropriate forums.


> > Are we in the tomcat-user forum ???
> > I don't see the relationship between a so simple constructor problem
> > (which Javadoc solve quiet easily ...) and Tomcat ...
> >
> >
> > Alistair Hopkins a �crit :
> > >
> > > 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 [mailto:Michael.Wentzel@aswethink.com]
> > > Sent: Friday, April 06, 2001 12:58 PM
> > > To: 'tomcat-user@jakarta.apache.org'
> > > 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
> > > cell
> > >
> > > (formatted like so: e.g.  2001-03-23 13:04:59)
> > >
> > >  and retrieve the date that is exactly 7 days earlier than the retrieved
> > > date.
> > >
> > > 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,
> > > DateTest.java:20: 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
> > > java.sql.Date.
> > > Therefore, when you code Date d = new Date() the compiler doesn't know
> which
> > > classdef
> > > 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 - http://www.aswethink.com
> >
> > --
> > Cordialement,
> >
> >
> > St�phane BAUDET
> >
> > _________________________________________________________
> > GL Trade
> > 48, rue Notre Dame des Victoires - 75002 Paris
> > Tel : 01 53 40 43 12 (interne 1312)
> > Fax : 01 53 40 01 40
> > Email : sbaudet@gltrade.fr
> > _________________________________________________________
> 

Milt Epstein
Research Programmer
Software/Systems Development Group
Computing and Communications Services Office (CCSO)
University of Illinois at Urbana-Champaign (UIUC)
mepstein@uiuc.edu


Re: Dates in Java

Posted by Martin Mauri <mm...@profesi.com.ar>.
Hey...don't be so rude, let the boys work their problems out...


> Are we in the tomcat-user forum ???
> I don't see the relationship between a so simple constructor problem
> (which Javadoc solve quiet easily ...) and Tomcat ...
>
>
> Alistair Hopkins a écrit :
> >
> > 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 [mailto:Michael.Wentzel@aswethink.com]
> > Sent: Friday, April 06, 2001 12:58 PM
> > To: 'tomcat-user@jakarta.apache.org'
> > 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
> > cell
> >
> > (formatted like so: e.g.  2001-03-23 13:04:59)
> >
> >  and retrieve the date that is exactly 7 days earlier than the retrieved
> > date.
> >
> > 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,
> > DateTest.java:20: 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
> > java.sql.Date.
> > Therefore, when you code Date d = new Date() the compiler doesn't know
which
> > classdef
> > 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 - http://www.aswethink.com
>
> --
> Cordialement,
>
>
> Stéphane BAUDET
>
> _________________________________________________________
> GL Trade
> 48, rue Notre Dame des Victoires - 75002 Paris
> Tel : 01 53 40 43 12 (interne 1312)
> Fax : 01 53 40 01 40
> Email : sbaudet@gltrade.fr
> _________________________________________________________


Re: Dates in Java

Posted by Stéphane BAUDET <sb...@gltrade.fr>.
Are we in the tomcat-user forum ??? 
I don't see the relationship between a so simple constructor problem
(which Javadoc solve quiet easily ...) and Tomcat ...


Alistair Hopkins a écrit :
> 
> 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 [mailto:Michael.Wentzel@aswethink.com]
> Sent: Friday, April 06, 2001 12:58 PM
> To: 'tomcat-user@jakarta.apache.org'
> 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
> cell
> 
> (formatted like so: e.g.  2001-03-23 13:04:59)
> 
>  and retrieve the date that is exactly 7 days earlier than the retrieved
> date.
> 
> 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,
> DateTest.java:20: 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
> java.sql.Date.
> Therefore, when you code Date d = new Date() the compiler doesn't know which
> classdef
> 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 - http://www.aswethink.com

-- 
Cordialement,


Stéphane BAUDET

_________________________________________________________
GL Trade
48, rue Notre Dame des Victoires - 75002 Paris
Tel : 01 53 40 43 12 (interne 1312)
Fax : 01 53 40 01 40
Email : sbaudet@gltrade.fr
_________________________________________________________

RE: Dates in Java

Posted by Alistair Hopkins <al...@berthengron.co.uk>.
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 [mailto:Michael.Wentzel@aswethink.com]
Sent: Friday, April 06, 2001 12:58 PM
To: 'tomcat-user@jakarta.apache.org'
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
cell

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

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

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,
DateTest.java:20: 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
java.sql.Date.
Therefore, when you code Date d = new Date() the compiler doesn't know which
classdef
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 - http://www.aswethink.com


RE: Dates in Java

Posted by Arnaud Vandyck <ar...@ressource-toi.org>.
On Fri, 6 Apr 2001, Michael Wentzel wrote:

tc> For example, 
tc> DateTest.java:20: cannot resolve symbol
tc> symbol  : constructor Date  ()
tc> location: class java.sql.Date
tc>                 Date d = new Date();
tc>                          ^

You got to explicitly tell which Date object you want to use:

ex.: java.util.Date d = new java.sql.Date((Long)l);

You can also look at the java.text.SimpleDateFormat class:

java.lang.Object
  |
  +--java.text.Format
        |
        +--java.text.DateFormat
              |
              +--java.text.SimpleDateFormat

Regards.

--
Arnaud Vandyck <http://www.ressource-toi.org/>
"N'a que l'rogneux qui s'grette."