# How to contrainst a thing when that day is already booked?

**URL:** <https://forum.bubble.io/t/how-to-contrainst-a-thing-when-that-day-is-already-booked/217819>\
**Category:** Need help\
**Created:** [July 30, 2022, 9:04pm UTC](https://forum.bubble.io/t/how-to-contrainst-a-thing-when-that-day-is-already-booked/217819 "2022-07-30T21:04:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Viktor](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/viktor/32/134100_2.png) [@Viktor](https://forum.bubble.io/u/Viktor)\
**Post date:** [July 30, 2022, 9:04pm UTC](https://forum.bubble.io/t/how-to-contrainst-a-thing-when-that-day-is-already-booked/217819/1 "2022-07-30T21:04:22Z")

</div>

Hey guys, its been too long since I’ve used bubble, so, a bit of a silly question here… I’ve made a organizational app for booking rooms at night. Its 95% done, but I still didn’t figure out the **best way to show the rooms available.**

- ![Captura de tela de 2022-07-30 18-05-26](https://us1.discourse-cdn.com/bubble/original/3X/d/d/dd12f4f3288d994be313109e0a8c088dd5e6bfd6.png)  
**I need the room dropdown to only show the rooms that available** , that is, that don’t have any booking between the start date and the end date.

**The current way I do this** , is to save all days between start and end date in each booking. Then in the form’s dropdown, I can constraint the “Do a search for Rooms” for bookings that dosn’t contain “do a search for Bookings” that list of days. But this is too slow and seems wrong at all angles… **Do you know of a better idea to do this?**

\*It’s night booking. So I can start a new booking today (afternoon) even if that room had a booking ending today(this morning). I don’t know if that makes a difference…

---

<div class="post-metadata">

**Author:** ![viquarahmed07](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/viquarahmed07/32/145585_2.png) [@viquarahmed07](https://forum.bubble.io/u/viquarahmed07)\
**Post date:** [July 30, 2022, 9:08pm UTC](https://forum.bubble.io/t/how-to-contrainst-a-thing-when-that-day-is-already-booked/217819/2 "2022-07-30T21:08:27Z")

</div>

@Viktor  
I think you need to use date ranges.  
Here is the link which quietly resemble your scenario

> [@\[New Feature\] Date and Number Range support](http://forum.bubble.io/t/new-feature-date-and-number-range-support/6194):
>
> We’ve announced that we were working on this a few days ago. We’ve added two data types to Bubble and search support for them. You can define a date range (defined with 2 dates) and a number range. This will be especially useful if you want to build a booking system a la Airbnb, etc. To define a date range, you should define such a field on a type use two dates (for instance 2 inputs), and do this Then to perform some searches, you can search for entries whose range are contained, …

---

<div class="post-metadata">

**Author:** ![Viktor](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/viktor/32/134100_2.png) [@Viktor](https://forum.bubble.io/u/Viktor)\
**Post date:** [July 30, 2022, 9:34pm UTC](https://forum.bubble.io/t/how-to-contrainst-a-thing-when-that-day-is-already-booked/217819/3 "2022-07-30T21:34:56Z")

</div>

> [@viquarahmed07](#):
>
> Here is the link which quietly resemble your scenario

Thanks @viquarahmed07. I did look in to range option but I think I misunderstood its explanation. I will look deeper with videos and such, maybe I’m just too slow today hahah. Thanks for your time during the weekend, mate!

---

<div class="post-metadata">

**Author:** ![rpetribu](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/rpetribu/32/90852_2.png) [@rpetribu](https://forum.bubble.io/u/rpetribu)\
**Post date:** [July 30, 2022, 10:45pm UTC](https://forum.bubble.io/t/how-to-contrainst-a-thing-when-that-day-is-already-booked/217819/4 "2022-07-30T22:45:12Z")

</div>

Hi @Viktor 👋

Ok, I assume you have a datatype called **Rooms** with all your rooms…

Every booking should have

- Room (Type = Room)
- Check-in Date (Type = Date)
- Check-out Date (Type = Date)

To find the availables rooms you will have to know the ones that are already booked in the period between your Datepickers.

You will have to do two searches.

→ The first one to find the Bookings where the **Check-in** dates are before **Datepicker1’s Value** and the **Check-out** dates are after **Datepicker2’s Value**

`Do a Search for Bookings:each item's Room`

→ The second one to find the Bookings where the **Check-in** dates are before **Datepicker2’s Value** and the **Check-out** dates are after **Datepicker2’s Value**

`Do a Search for Bookings:each item's Room`

Merging these to searches, you will have all the blocked rooms.

`Do a Search for Bookings:each item's Room merged with Do a Search for Bookings:each item's Room`

Save this list in a custom state called “Blocked rooms”.

Now, in your Dropdown, you just need to show **All Rooms** (just do a Search for Rooms without any constraint) minus the Blocked rooms list.

`Search for Rooms:minus list Blocked rooms`

This should work 👍

---

<div class="post-metadata">

**Author:** ![Viktor](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/viktor/32/134100_2.png) [@Viktor](https://forum.bubble.io/u/Viktor)\
**Post date:** [August 1, 2022, 3:03pm UTC](https://forum.bubble.io/t/how-to-contrainst-a-thing-when-that-day-is-already-booked/217819/5 "2022-08-01T15:03:51Z")

</div>

Thank you so much for your time, mate! I’m trying to test this out but I’m struggling even with a paid course. Jesus, I feel so dumb right now…

---

<div class="post-metadata">

**Author:** ![rpetribu](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/rpetribu/32/90852_2.png) [@rpetribu](https://forum.bubble.io/u/rpetribu)\
**Post date:** [August 1, 2022, 4:00pm UTC](https://forum.bubble.io/t/how-to-contrainst-a-thing-when-that-day-is-already-booked/217819/6 "2022-08-01T16:00:11Z")

</div>

Relax 😅

Let’s make it together…

In what part are you stuck in?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/bubble/original/3X/2/8/2847faa74692c2ffa5d939d3dc3724cdd060d247.png) [@system](https://forum.bubble.io/u/system)\
**Post date:** [October 8, 2022, 9:04pm UTC](https://forum.bubble.io/t/how-to-contrainst-a-thing-when-that-day-is-already-booked/217819/7 "2022-10-08T21:04:22Z")

</div>

This topic was automatically closed after 70 days. New replies are no longer allowed.
