function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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 for10 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

Shashikant SharmaShashikant Sharma

Even thouh I saw similar post like this copying my response so that you can see any of  them.

 

 

Like in your case if Close Date is 01/01/2011

 

Do you should create a list of Date

 

 

Date closeDate = Date.newInstance(2011 , 01 , 01);
List<Date> listDate = new List<Date>();
listDate.add(closeDate .adddays(19));
system.debug(listDate.get(0) + '    :  Date ');
for(integer i = 0 ; i < 13 ; i ++)
	{
             listDate.add(listDate.get(i).addMonths(1));
             system.debug(listDate.get(i+1) + '    :  Date ');
        }

 

I hope you can use above example. Please run this in system logs if you want thats why i used system.debug.

 

If close date is not always the first date of jan then you can get first date of monthe using 

 

toStartOfWeek method like it will : Returns the first of the month for the Date that called the method. For example, July 14, 1999 returns July 1,1999.