i am designing a page where the user enters the start date for a uni session say
04/02/2008 in dd/mm/yyyy format and then the user selects the duration for the session in weeks, say 22.
our system needs to calculate the end date for the session by adding 22 weeks to the start date...i can do this in real life by looking up a calender that shows week of the year....how do we do it programming.
we are using java/jsp, any suggestions please.

Use the SimpleDateFormat class to parse the string into a Date object. Feed that Date object to the instance of the Calendar object and use it's function roll() to do the dirty work for you. Something along the lines of:

public class DateHelper {
    public static void main(String args[]) throws ParseException {
        String dateStr = "13/01/2008";
        SimpleDateFormat sdf = new SimpleDateFormat("DD/mm/yyyy");
        Date dt = sdf.parse(dateStr);
        Calendar cal = Calendar.getInstance();
        cal.setTime(dt);
        cal.roll(Calendar.WEEK_OF_YEAR, 22);    //add 22 weeks
        Date newDt = cal.getTime();
        System.out.println("Training from " + dt + " to " + newDt);
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.