This is the way I would do it, which will allow it be
portable to any database.
Calendar c = Calendar.getInstance();
c.add(Calendar.DATE,-7);
//Connection is assumed
PreparedStatement stmt = conn.prepareStatement("select
* from sometable where somedatetimefield = ?");
stmt.setTimestamp(1,new
Timestamp(c.getTime().getTime()));
--- Ryan <[EMAIL PROTECTED]> wrote:
> 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
>
> -----
>
> thanx
> -ryan
>
=====
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Scott
__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail.
http://personal.mail.yahoo.com/