Validation for bookings across multiple days?

Morning all. I’m writing an app that books four rooms across multiple days. Works fine so far but I’m wondering how I could check validation when try to book to ensure that the same room hasn’t been booked for the same days. To throw a spanner in the works, it is ok if the first or last day of the booking overlaps with another booking for same room (as check out could be in morning allowing another check in in afternoon). I’m not worried about times, just dates.

Eg., Room One booked from 18 Sept to 25 Sept, therefore Room One can also be booked from 25 Sept to 27 Sept, or from 16 Sept to 18 Sept.

What would be the best way to approach this? Would really appreciate a point in the right direction as I’m just not sure. :grinning_cat: I’ve looked at the Simple Booking App tutorial from Loqode (as well as a number of others) but it makes a helper table for time slots on a set day… that wouldn’t work for me because I’m not doing time slots but days.

I would:

  • Find a way, e.g JavaScript, to get two dates (18 Sept and 25 Sept 2025) and then return an array of dates in numeric form, not including the final date. So in this case that would be “20250918, 20250920, 20250921, 20250922, 20250923, 20250924”.
  • Then, you would always have a list of dates that have been booked for a particular room through relations & joined lists.
  • Convert it to an array, and then do the same conversion for a new booking attempt.
  • Relate the booking attempt’s array of dates to the existing list of booked dates for a room. If a relation exists, then a booking can not be made.

Thanks for this. I will have a red hot crack at that :grinning_cat:

Hi all. I actually ended up working this out without the need for javascript. I stumbled across this post by @Darren_Murphy and after a bit of trial and error I got it working! Thanks Darren!

2 Likes