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

  • SEARCH
  • Home
  • 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 708999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:27:17+00:00 2026-05-14T04:27:17+00:00

I have a planning structure on two tables to store available slots by day,

  • 0

I have a planning structure on two tables to store available slots by day, and sessions.

A slot is defined by a range of time in the day.

CREATE TABLE slot (
  `id` int(11) NOT NULL AUTO_INCREMENT
, `date` date
, `start` time
, `end` time
);

Sessions can’t overlap themselves and must be wrapped in a slot.

CREATE TABLE session (
  `id` int(11) NOT NULL AUTO_INCREMENT
, `date` date
, `start` time
, `end` time
);

I need to generate a list of available blocks of time of a certain duration, in order to create sessions.

Example:

INSERT INTO slot
  (date, start, end)
VALUES
  ("2010-01-01", "10:00", "19:00")
, ("2010-01-02", "10:00", "15:00")
, ("2010-01-02", "16:00", "20:30")
;

INSERT INTO slot
  (date, start, end)
VALUES
  ("2010-01-01", "10:00", "19:00")
, ("2010-01-02", "10:00", "15:00")
, ("2010-01-02", "16:00", "20:30")
;

2010-01-01

   <##><####>                               <- Sessions
 ------------------------------------       <- Slots
10  11  12  13  14  15  16  17  18  19  20

2010-01-02

         <##########>          <########>   <- Sessions
 --------------------    ------------------ <- Slots
10  11  12  13  14  15  16  17  18  19  20

I need to know which spaces of 1 hour I can use:

+------------+-------+-------+
| date       | start | end   |
+------------+-------+-------+
| 2010-01-01 | 13:00 | 14:00 |
| 2010-01-01 | 14:00 | 15:00 |
| 2010-01-01 | 15:00 | 16:00 |
| 2010-01-01 | 16:00 | 17:00 |
| 2010-01-01 | 17:00 | 18:00 |
| 2010-01-01 | 18:00 | 19:00 |
| 2010-01-02 | 10:00 | 11:00 |
| 2010-01-02 | 11:00 | 12:00 |
| 2010-01-02 | 16:00 | 17:00 |
+------------+-------+-------+
  • 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-14T04:27:17+00:00Added an answer on May 14, 2026 at 4:27 am

    I think you’re life is going to be a lot easier if you approach this algorithmically rather than using a query. That could be using a sproc and that could mean writing an algorithm in the middle tier.

    My recommendation is to just do it in the middle tier. Make the database responsible for storing the slots and sessions and leave the computations to something better suited to the task.

    Databases are for persisting knowledge, not hosting business logic.

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

Sidebar

Related Questions

I have a RelativeLayout with different elements. I was planning to have two ListViews
I'm working on a game (using Ruby) and planning to have it available in
im planning to create a movie file that might have over 16,000 frames?i know
I'm planning to have 20 or more sites in the same database tables. Like
I'm planning to have collection of items stored in a TCollection. Each item will
I have a personal project I'm planning and I came to a small hurdle.
I have a client with an event planning site asking his pages to fade
I have a C library that I'm planning to use in an iPhone application.
I have a website that I made and I am planning to redo it.
I was planning on trying out Re-Fox: http://www.refox.net/ They have a demo version -

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.