2

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

Community
  • 1
  • 1

3 Answers3

6

You can use the Calendar class:

Calendar cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_YEAR , -45);
MByD
  • 133,244
  • 25
  • 260
  • 270
2

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.

Community
  • 1
  • 1
tofutim
  • 21,324
  • 20
  • 81
  • 144
1

Use Joda Time. :-)

import org.joda.time.DateTime;

DateTime dt = new DateTime().minusDays(45);

// Convert to java.util.Date
Date d = dt.toDate();
missingfaktor
  • 88,931
  • 61
  • 278
  • 362