Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 192263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:24:41+00:00 2026-05-11T16:24:41+00:00

In my question about searching for date ranges I tried simplifying the problem and

  • 0

In my question about searching for date ranges I tried simplifying the problem and inadvertently posed a different and simpler problem.

Rather than complicate that question with an edit I am going to ask the problem I actually intended.

I have two tables Property and Booking. Bookings have a foreign key to Properties and also start and end date.

The user is searching for free slots and supplies a desired duration in days. They also supply a range of start dates that they are interested in. Therefore a search will be along the lines of:
“Find me all properties I want a 3 day slot which starts anytime in May.”

Now I can do this by:
1. Running 31 queries for each potential start day
2. Finding all bookings in May, condense them into one array of 31 booleans representing days and loop through looking for slots.

I assume (2) is more efficient in most cases. Is there any better algorithms? Is there a pure SQL solution.

I will be using Django and my dataset is small so I will probably be OK with a ‘dumb’ approuch but I am curious to know what the best algorithm looks like.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T16:24:41+00:00Added an answer on May 11, 2026 at 4:24 pm

    Probably overkill for your application – but:

    A relatively simple way of improving your searches at the expense of making the ‘write’ process more complicated, would be to change the Booking table to make it an ‘Availability’ table.

    Add in a boolean column to indicate if the slot is free or booked (or better still put in the id of the customer who’s booked it, and use 0 if the slot is free).

    Start off with a single free slot, 1st Jan 2009 -> 31st Dec 20??

    When you get a booking split the free slot into 3 (two inserts and one update), the booked slot and the two available slots.

    Keep doing that and as the time frame gets more fragmented the booking process will consist of one of the following:

    • Assigning an entire ‘available slot’ to someone (one update)
    • Splitting an ‘available slot’ into two (one update and one insert)
    • Splitting a slot into 3 (as above) if someone books the middle section out of an available slot.

    That’s not incredibly complicated to manage and the search process becomes a simple query: finding any slots in the required time frame that are available (booked=false or customerid=0, whichever way you go with it) where enddate – startdate >= the number of days you want.

    It doubles the size of the booking/availability table, and makes bookings less simple, but the trade off is that the search process is about as easy as it gets.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 138k
  • Answers 138k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Thanks to a little guided digging, with help from John,… May 12, 2026 at 7:35 am
  • Editorial Team
    Editorial Team added an answer Actually the problem was with cache on the computer. Even… May 12, 2026 at 7:35 am
  • Editorial Team
    Editorial Team added an answer Try doing the following: UINavigationBar *bar = self.navigationController.navigationBar; bar.titleView =… May 12, 2026 at 7:35 am

Related Questions

I'm a Scrum newbie and looking to implement Scrum in my company. Obtaining buy-in
EDIT : To people building tagging systems. Don't read this. It is not what
We have a hosted application that manages pages of content. Each page can have
I am sure that this kind of questions must have been asked before, but

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.