Multi-Day Booking system {{Solved}}

Hi all, I have built 2 different booking systems that works perfectly fine in their own respect. It books different services on a day and blocks out times that are selected.

I now have a request to build an app for a camping ground to do their bookings. Customers would typically choose a stand and the From-To Date, I am finding it impossible to get a solutions where I get an array built with the values starting with the From Date and ending with the To Date.

I have used up my tokens on ChatGPT and Groq for 4 days straight and cannot get a snippet of formula that can generate such an Array.

Any pointers?

You might want to use JavaScript column and a snippet from this Stack Overflow post:

You would be able to set the start date column and the end date column as p1 and p2 in the JS column to return an array of dates.

Is this solely for preventing duplicate bookings?

Yes, If you have a beter solution to prevent duplicate bookings, please share.

I managed to get the correct output by modifying one of the snippets a bit. You have to make sure to use a FORMAT DATE column to format the date to this:
yyyy-MM-dd

Then I modified one of the snippets a bit, and this gave me the right output of all the days in an array.

function getDaysArray(start, end) {
let arr = ;
let dt = new Date(start);

while (dt <= end) {
    arr.push(new Date(dt)); // Push each date into the array
    dt.setDate(dt.getDate() + 1); // Move to the next day
}

return arr;

}

// Use the function
const daylist = getDaysArray(new Date(p1), new Date(p2));
return daylist.map(v => v.toISOString().slice(0, 10)).join(“|”);
// Returns as “2018-05-01|2018-05-02|…”

Be careful with that. The format date column has been known to give inconsistent results on different devices and in different regions. Some of us don’t trust it, and try to avoid it altogether. A more reliable approach is to use a Math column:

Year(Date)*10^4
+Month(Date)*10^2
+Day(Date)