Add month in date

Reply

Join Date: Dec 2007
Posts: 11
Reputation: shweta797 is an unknown quantity at this point 
Solved Threads: 0
shweta797 shweta797 is offline Offline
Newbie Poster

Add month in date

 
0
  #1
May 27th, 2008
Dear sir
In my project i have to show amount of all the months i.e if user enter first due date and expiry date then it calculate the amount of all the months which are between first due date and expiry date in reports. in Jsp how a month can be added in a table date value.
if my filelds are :

  1. java.sql.Date duedate=rs.getDate("firstrentduedate");
  2.  
  3. java.sql.Date expirydate =rs.getDate("expiryofrent");
  4. while(duedate .after(expirydate))
  5. {
  6. duedate=duedate+'addmonth'
  7. }
plz help
Last edited by peter_budo; May 27th, 2008 at 9:46 am. Reason: Keep It Organized - please use [code] tags
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,467
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 267
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: Add month in date

 
0
  #2
May 27th, 2008
Use Calendar and its add method.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Add month in date

 
0
  #3
May 27th, 2008
but don't do it in a JSP.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 11
Reputation: shweta797 is an unknown quantity at this point 
Solved Threads: 0
shweta797 shweta797 is offline Offline
Newbie Poster

Re: Add month in date

 
0
  #4
May 28th, 2008
Originally Posted by masijade View Post
Use Calendar and its add method.
Can You specify some code for it

Thanks
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,467
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 267
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: Add month in date

 
1
  #5
May 28th, 2008
  1. Calendar c = Calendar.getInstance();
  2. c.setTime(date);
  3. c.add(field, amount);
  4. c.getTime();

Read the API docs, they contain more than enough information for this sort of thing.

As mentioned, however, you should not be doing this in a JSP. Scriptlets have no place anymore in a JSP. They are only still allowed so as not to break old JSP (i.e. backwards compatability) but you should not be creating any new scriptlets. Use a Bean.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 1965 | Replies: 4
Thread Tools Search this Thread



Tag cloud for JSP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC