|
-
August 28th, 2001, 10:33 AM
#1
Date minus X days
I'm trying to write something that accepts a date in yyyymmdd format and a number that will give me the date minus that number.
For example, if I pass in 20010403 and 2, I should return 20010401.
Here's what I have so far, but am stuck:
public static String DateRoller(String strDate, int intDaysToRoll)
{
java.util.Calendar rcal = null;
rcal = GregorianCalendar.getInstance();
for(int i = 1;i<intDaysToRoll;i++)
{
rcal.roll(rcal.DATE,false); //Roll back 1 day...
}
Date curDate = rcal.getTime();
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyymmdd");
return sdf1.format(curDate);
} //End DateRoller
Currently it doesn't take the date I pass into consideration, but even the current date doesn't roll back the way it should...
Any suggestions?
Thanks!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|