The start and end dates are submitted initially through a form. Then I want to extract the list of months and have them available to be used as choices in another form.
var start= new Date(p1);
var start1= new Date(start.setDate(1));
var end = new Date(p2);
var res='';
var difference = (end.getFullYear()*12 + end.getMonth()) - (start.getFullYear()*12 + start.getMonth())+1;
for(var i=0; i<difference; ++i){
var newDate = new Date(start.setMonth(start1.getMonth()+i));
var month = newDate.toLocaleString('default', { month: 'long' });
res=res+month+', ';
}
return res
Then use the split column to create an array… then turn that array into a list.
Or, if you don’t need months in one string… then you can use this code to create a list… but first copy the start and end date to all rows using a single value column… add a row number column starting from 0:
var start= new Date(p1);
var start1= new Date(start.setDate(1));
var end = new Date(p2);
var res='';
var difference = (end.getFullYear()*12 + end.getMonth()) - (start.getFullYear()*12 + start.getMonth())+1;
if(difference>p3){
var newDate = new Date(start.setMonth(start1.getMonth()+p3));
var month = newDate.toLocaleString('default', { month: 'long' });
res=month;
}
return res