• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Add 7 days to given date and end date in jsp

 
Intan Syafiqah
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your advice....i will follow it.... =)
 
Wayan Saryada
Ranch Hand
Posts: 105
IntelliJ IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you use Joda-Time you can do something like:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic