+ Start a Discussion
venkatasubhashkvenkatasubhashk 

Iterate Date value to 20 th of Every month referring from CLOSEDATE

HI,
I cerated a controller where i add New Opportunities on a Visual force Page ,
i have a field closedate which i should iterate and set to 20 th of every month 
i have code like this


for(i=0;i<14;i++) 

{        

Opportunity LitOrd = new Opportunity();
 LitOrd.closedate = o.closedate;
 Opps.add(LitOrd);

}


so for 10 opportunities i am getting closedate as the current page closedate from where button is clicked on a Opportunity


is there a way i can get 20 th of every month for 14 months


say CLosedate = 1/1/2011


so for 14 months i should get like following on VF Page... 


1)  closedate = 20/01/2011

2)  closedate = 20/02/2011

3)  closedate = 20/03/2011

4)  closedate = 20/04/2011

5)  closedate = 20/05/2011

6)  closedate = 20/06/2011

7)  closedate = 20/07/2011

8)  closedate = 20/08/2011

9)  closedate = 20/09/2011

10) closedate = 20/10/2011

11) closedate = 20/11/2011

12) closedate = 20/12/2011
13) closedate = 20/01/2012

14) closedate = 20/02/2012


is there a way to chieve this in Class or Visualforce page Level

TheSwamiTheSwami

Use the addMonths function - here is an example:

 

Date today = System.today();
for (Integer i=0;i<14;i++) { 
  System.debug(today.addMonths(i));
}