I’m using Javascript column but it is not giving result in Glide, already tested in compiler. It works.
I’m on free version of Glide, if this is an issue, which plan should get?
The purpose is, to get selected amout of monthes starting from month selected.
For example. 6 monthes from November 2023
The result should be. “November 2023, December 2023, January 2024, February 2024, March 2024, April 2024”
The code
const monthNames = [
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
];
let startIndex = monthNames.indexOf(startMonth);
let currentYear = startYear;
let resultMonths = [];
for (let i = 0; i < monthsCount; i++) {
let currentIndex = (startIndex + i) % 12;
// Increment the year when the month wraps around to January
if (currentIndex === 0 && i !== 0) {
currentYear++;
}
resultMonths.push(monthNames[currentIndex] + " " + currentYear);
}
return resultMonths.join(", ");
}
// Example usage:
const startMonth = "November"; // Starting month
const startYear = 2023; // Starting year
const monthsCount = 6; // Number of months to list
const result = listMonths(startMonth, startYear, monthsCount);
console.log(result); // Correct Output: "November 2023, December 2023, January 2024, February 2024, March 2024, April 2024"