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 7873759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:36:24+00:00 2026-06-03T02:36:24+00:00

I am having trouble validating days with a reservation system I have to build

  • 0

I am having trouble validating days with a reservation system I have to build (PHP/Mysql).
I posted a similar question earlier Reservation system dates But something changed.

The problem I am having;
We have a studio/conference room available at office. This is up for rent on a limited time scale. The user select on what day,time and how many hours he will want to rent the room.

Reservation step by step:

1- The user selects the month in which he wants to rent the studio.
2- The user selects the day on which he wants to rent the studio. (here i get stuck)
3- The user selects the time on which he wishes to get the key.

Time on which the key is receivable:

00:00:00 - 06:00:00
06:00:00 - 12:00:00
12:00:00 - 18:00:00
18:00:00 - 24:00:00

These times are the times, in which the user is will receive the key for the door.

4- The user selects the amount of hours he wishes to rent the studio.

The problem:
I am able to check on what days the studio is rented but not exactly what time.
I know how to check on time in PHP. But for example;

User 1 rents the studio on 27th April 2012 from 12:00:00 until 18 hours later.
User 2 wants to rent the studio on 26th April 2012 from 18:00:00 until 12 hours later.
User 3 wants to rent the studio on 28th April.

How would I be able to check if User 2 can rent the studio until max 27th april 12:00:00.
And how is it possible to check if User 3 can rent the studio on the 28th and make sure it is available after 06:00 .

Database:

id                 int(11)
user_id             int(11)
rental_name         varchar(255)
key_receive_time varchar(255)
start_date         int(11)
end_date         int(11)
total_hours      int(11)

I have been at this for 2 days in a row now and still can’t crack it. I suppose the solution is simple but I probably search in the wrong direction.

Thanks in advance.

EDIT example queryie:

SELECT * FROM reservations
WHERE (start_date >= " . $start_block_1 . " AND end_date <= " . $end_block_1   . ")
OR    (start_date >= " . $end_block_1   . " AND end_date <= " . $start_block_1 . ")

The $start_block_1 and $end_block_1 represent the timestamp 00:00:00 – 06:00:00 blocks of a day .

I perform this query 4 times for there are 4 blocks in the day on which the user can pickup the key.

  • 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-06-03T02:36:26+00:00Added an answer on June 3, 2026 at 2:36 am

    Seems like you need to check if an interval — a pair of start and end date — conflicts with existing intervals in your database. If this is what you want then here is the query:

    -- //// FOR TESTING \\\\
    CREATE TABLE reservations (start_date INT, end_date INT);
    
    INSERT INTO reservations(
        start_date,
        end_date
    )
    VALUES (
        UNIX_TIMESTAMP('2012-04-27 12:00:00'), -- start date booked by user 1
        UNIX_TIMESTAMP('2012-04-28 06:00:00')  -- end date booked by user 1
    );
    
    SET @d1 = UNIX_TIMESTAMP('2012-04-26 18:00:00'); -- start date requested by user 2
    SET @d2 = UNIX_TIMESTAMP('2012-04-27 06:00:00'); -- end date requested by user 2
    -- \\\\ FOR TESTING ////
    
    SELECT 1
    FROM reservations
    WHERE
    (@d1        <= start_date AND start_date <  @d2     ) OR -- start datetime lies "inside" the interval
    (@d1        <  end_date   AND end_date   <= @d2     ) OR -- end datetime lies "inside" the interval
    (start_date <= @d1        AND @d2        <= end_date)    -- the interval itself lies inside start and end datetime
    

    The query will return the rows that conflict with the given interval. The variables @d1 and @d2 are for testing your queries in a mysql client; replace them with data passed in from PHP code.

    Note: the comparison operators < and <= might need to be changed depending on whether your start/end datetimes are inclusive or exclusive.

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

Sidebar

Related Questions

I am having trouble validating user input, I have the following loop which definitely
I am having trouble validating my xml schema. I get these errors on the
I'm having trouble validating an HTML form with JavaScript. On their own they each
I'll admit, I'm an XML newbie. I'm having trouble validating some xml against a
I'm having trouble with some Excel data validation. On one sheet, I have a
Having Trouble with Entity Framework. I have been populating EntityReferences with an EntityKey inorder
I am having some trouble understanding how to make System Sequence Diagrams, as I
I have a form on my page that I am having trouble receiving a
I am having trouble validating my html, my menus are triggering the following error:
I am having trouble validating serialized data. Ok, so I started with an XSD

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.