aspose file tools*
The moose likes JSP and the fly likes Add 7 days to given date and end date in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Add 7 days to given date and end date in jsp" Watch "Add 7 days to given date and end date in jsp" New topic
Author

Add 7 days to given date and end date in jsp

Intan Syafiqah
Greenhorn

Joined: May 05, 2012
Posts: 11
hello...

I want to ask...

How can i get the days that add 7 day given early date and end date..
For example i insert early date is 10-05-2012 and end date is 06-06-2012...

The output should be

10-05-1012
17-05-2012
24-05-2012
31-05-2012

I really not good went it play with the date..
Hope that anyone can help me to solve this problem.

I really appreciate your help..

Thank you.
Isuru Jay
Greenhorn

Joined: May 09, 2012
Posts: 7

Use this buddy

String date1 = "10-05-2012";
String date2 = "06-06-2012";

SimpleDateFormat sim = new SimpleDateFormat("dd-MM-yyyy");

Calendar calendar = Calendar.getInstance();
Calendar calendar2 = Calendar.getInstance();

try {

calendar.setTime(sim.parse(date1));
calendar2.setTime(sim.parse(date2));

while(calendar.compareTo(calendar2)<=0){
System.out.println(sim.format(calendar.getTime()));
calendar.add(Calendar.DATE, 7);
}



} catch (ParseException e) {
e.printStackTrace();
}
Intan Syafiqah
Greenhorn

Joined: May 05, 2012
Posts: 11
Thanks to you..

i get it....i can solve it based on your coding that give it to me...

Thank you so much..
Piyush Mangal
Ranch Hand

Joined: Jan 22, 2007
Posts: 196
Please do not put this code in your JSP. Have a servlet do this calculation and then forward the request to jsp.
Intan Syafiqah
Greenhorn

Joined: May 05, 2012
Posts: 11
Thanks for your info..

but i want to ask one more thing..
why i can not put this coding in JSP..
how can i put this looping date in database.
when i run it into file.java it can run...
but it can not function in JSP to database..
how i want to pun this date in database...

i really need your help...
Intan Syafiqah
Greenhorn

Joined: May 05, 2012
Posts: 11
Thanks for that person who give me the coding...
based on your coding i can do it in JSP and insert the date in database.....

=)
Isuru Jay
Greenhorn

Joined: May 09, 2012
Posts: 7

You are welcome buddy. but as Piyush said it is better not to do cording in your jsp file. It will damage your MVC architecture.
Intan Syafiqah
Greenhorn

Joined: May 05, 2012
Posts: 11
thanks for your advice....i will follow it.... =)
Wayan Saryada
Ranch Hand

Joined: Feb 05, 2004
Posts: 105

If you use Joda-Time you can do something like:



Website: Learn Java by Examples
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Add 7 days to given date and end date in jsp