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
AzusfdcAzusfdc 

My requirement first need to get dynamic date values from past 2 years that should be added in a list of selectoptions and date in format of Feb-2016 could any body help ?

James LoghryJames Loghry
If you want to do this via Apex, you could use the Datetime.now variable and the addMonths method, looping through the past 24 months.  Then you'd use Datetime's format('formatString') method to format the Month / Year.  Here's an untested example:
 
List<SelectOption> options = new List<SelectOption>();
Datetime dtnow = Datetime.now();
for(Integer i=0; i < 24; i++){
    //Use a negative integer to subtract the month
    Datetime current = dtNow.addMonths(-1*i);
    String formattedStr = current.format('MMM-YYYY');
    dateStrings.add(new SelectOption(formattedStr,formattedStr));
}