I need to add 28 days to a Date – I have tried this:
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
Date date1 = df.parse("01/10/2012");
long week = 1000 * 60 * 24 * 7;
date1.setTime(date1.getTime() + week);
but I got an error on this line: Date date1 = df.parse("01/10/2012");
the error: Type mismatch: cannot convert from java.util.Date to java.sql.Date
I also tried this:
Date Mydate = new Date(02,04,2012);
Calendar cal = Calendar.getInstance();
cal.setTime(Mydate);
cal.add(Calendar.DATE, 10); // add 10 days
Mydate = (Date) cal.getTime();
but I got an error when trying to see the Mydate value.
You need to change this line:
to this:
Once you’ve done that, I think the best approach is: