Possible Duplicate:
Anyone know a simple way using java calendar to subtract X days to a date?
Hi ,
Could anybody please tell me how can we subtract 45 days from the current sysdate ??
Thanks
Possible Duplicate:
Anyone know a simple way using java calendar to subtract X days to a date?
Hi ,
Could anybody please tell me how can we subtract 45 days from the current sysdate ??
Thanks
You can use the Calendar class:
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_YEAR , -45);
Duplicate of How to subtract X days from a date using Java calendar?. You can use the add function with negative days, e.g., add(Calendar.DATE, -5).
See http://download.oracle.com/javase/6/docs/api/java/util/Calendar.html for the fine details.
Use Joda Time. :-)
import org.joda.time.DateTime;
DateTime dt = new DateTime().minusDays(45);
// Convert to java.util.Date
Date d = dt.toDate();