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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:37:37+00:00 2026-06-15T22:37:37+00:00

I have a table that has two fields dt(DateTime) and isblocked(Bit) What I’ve been

  • 0

I have a table that has two fields dt(DateTime) and isblocked(Bit)

enter image description here

What I’ve been trying to do is find the time span between two dates/times where there is 45 mins continuously free – based on a start date/time.

for example: based on the table above using 2012-12-11 13:30:00′ as my start date.
I would need values like this:

2012-12-11 15:30:00
2012-12-11 16:45:00

I have tried some min and max queries, like:

SELECT MIN(dt), isbooked
FROM booking
WHERE dt >= '2012-12-11 13:30:00' AND isbooked = 1
GROUP BY dt
LIMIT 1;

But I can’t seem to get the right structure together. If more information is needed just let me know.

  • 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-15T22:37:37+00:00Added an answer on June 15, 2026 at 10:37 pm

    In MySQL you can do this with a correlated subquery:

    select min(b.dt) as StartTime, NotBookedTime as EndTime
    from (select b.*,
                 (select min(b2.dt) from booking b2 where b2.dt >= b.dt and b2.isbooked = 1
                 ) as NotBookedTime
          from booking b
         ) b
    where b.isbooked = 0
    group by NotBookedTime
    having date_add(min(b.dt), interval 45 minute) <=  NotBookedTime
    

    What this does is find the first booked interval for each record, and remembers the time. It then finds the first booked interval, and checks when the difference is 45 minutes or larger.

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

Sidebar

Related Questions

I have a table that has two datetime columns (one for start time and
I have one table that has two fields - ID1 and ID2 ID1 can
I have a table, myTable that has two fields in it ID and patientID
I have a mysql table that has two fields that store the same type
I have a database table that has two fields , date and name. I
I have a table that has two columns: CommunityID PersonID And A People table
I have a city table that has two columns from_city to_city now lets assume
I have created a table in Visual Studio. That table has two columns. First
I have a table, tblNoComp, that has two columns, both foreign keys pointing to
I have a large table (~1M rows now, soon ~10M) that has two ranked

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.