List of Months between to Dates

Hey everyone,

I have been struggling with the following and I would really appreciate your help.

The user inputs a start date and an end date I want to get a list of the months so I use them as choices in a drop down list.

Example:
Start Date: 1st of September
End Date: 15th of December
Output: September, October, November, December (as text)

The dates can vary so it has to be dynamic and the output needs to be in a way that can be then used in the form.

Thanks a lot in advance!

Is this happening in a form or a details screen?

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.

Use the Java column and paste this code:

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
1 Like

This is exactly what I was looking for. Thank you Sir!

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.