Re: Subtracting a day from java.sql.Date
Mike Cronin <[email protected]>
| Newsgroups | gmane.comp.java.sun.servlet |
|---|---|
| Message-ID | <[email protected]> |
Hey Kenny,
FYI...
// Establish a Date object
Date d = new Date();
// Establish a Calendar object
Calendar cal = Calendar.getInstance();
// Set the Calendar object to your date
cal.setTime(d);
// Subtracts 5 days from the date
cal.add(Calendar.DATE, -5);
// Increments the date by one
cal.roll(Calendar.DATE, true);
// Decrements the date by one
cal.roll(Calendar.DATE, false);
// Convert the Calendar object back to a Date
Date newDate = new Date(cal.getTime().getTime());
Hope this helps.
Best Regards,
Mike
-----Original Message-----
From: A mailing list for discussion about Sun Microsystem's Java Servlet
API Technology. [mailto:[email protected]] On Behalf Of
Kenny G. Dubuisson, Jr.
Sent: Tuesday, May 20, 2003 12:54 PM
To: [email protected]
Subject: Subtracting a day from java.sql.Date
Hello all. I'm trying to subtract a day from a java.sql.Date class
variable. Looking at the java docs, there is no method to do this. All
the
date modification methods belong to another class, java.util.Calendar.
To
be able subtract a day from my class, should I convert it to the
Calendar
class and then back to the Date class or is there something easier that
I'm
missing. My main requirement is to have it in a java.sql.Date class
when
done. Any example code would be much appreciated (I have to admit I'm
still
a lightweight in Java).
Thanks,
Kenny
________________________________________________________________________
___
To unsubscribe, send email to [email protected] and include in the
body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [email protected] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html