Array of dates between 2 dates - experimental column

Hi Community,

I use the calendar on Glide page. To display a slot I need a start date and a end date.
It’s displayed like a slot on the app, but in the database is not possible to know days booked between the start and the end date.

So I can booked a slot for example on the 5th of octobre on the example above. Currently I can’t displayed a message to say “Date not available”

I found a javascript to create an array of date between to date

function getDatesInRange(startDate, endDate) {
  const date = new Date(startDate.getTime());

  const dates = [];

  while (date <= endDate) {
    dates.push(new Date(date));
    date.setDate(date.getDate() + 1);
  }

  return dates;
}

const d1 = new Date('2022-01-18');
const d2 = new Date('2022-01-24');

console.log(getDatesInRange(d1, d2));

When I tried the code on this tools it works perfect ! I get the array.

I tried to create an experimental column with this code, but it’s a fail !
Here is my code : glide-experimental-code-array-of-date-V2 - HTML, CSS, JS Repl - Replit

I read this topic : Date Hell - #7 by gvalero
to get the code of @Manu.n

Thanks all for your help :slight_smile:

Aymeric

I suspect that you don’t actually need any JavaScript here, but I’m not entirely clear on what the goal is.

Can you share some sample data, along with what the expected result would be?

Sorry I was unclear.

My goal is to allow people to book a flat thanks to this calendar.
1 person book 1 flat during a slot : Start date & end date
If another person want to book on the same slot, he is not allowed to book .

Here the process:

  • tap a button
  • open pop up
  • enter start date
  • enter end date
  • If one of these date is on a slot show a warning message and don’t allow to book the slot.

Okay, so what I would do:

  • Write both start and end dates to user specific columns
  • Use a pair of single value columns to apply those to all rows in your bookings table
  • Create an if-then-else column:
    – If SV Start Date is after Booking End Date, then null
    – If SV End Date is before Booking Start Date, then null
    – Else true
  • Then do a rollup on the if-then-else column, counting true values. If the result is greater than zero, then you have an overlapping date.

NB. I may not have the if-then-else logic exactly right there - I might have missed a condition or two - but it should give you the idea

3 Likes

Thanks Darren. I didn’t see this way to verify if a slot is open :slight_smile: I’m going to try it

Hola @Aymeric_de_Maussion , sorry for the late reply, I’ve been busy these days.

What Darren indicated above is the classic procedure to do these things but in my case, when I needed an array of dates for my booking APP was due to I used another flow/logic to get a booking.

The classic flow has 2 choices: Start Day and End Day and users have to mark both values in order to trigger the logic and receive a message:

  • Valid: There is an available slot. The process continues and APP asks for more info
  • Invalid: There is no an available slot. The user has to select another date(s) and the cycle starts over

My logic avoids asking for the End Day. The user only selects the Start Day and APP shows all available slots from this day. With this, the flow is easier and faster when the amount of busy slots is medium or high but to get this, I had to create an array of dates, sort it and use it in my logic.

Unfortunately I can’t show you my demo APP for this, I deleted one of my Glide Tables accidentally days ago and my logic got crazy :unamused: … I have to rebuild part of the APP and I haven’t had time to do it until now.

Anyway, if you are looking for an easy way to get a booking system, the @Darren_Murphy’s instructions are fine and can help you 90%. All depends on your needs and/or skills.

Have a great day, saludos!

4 Likes