473,883 Members | 1,730 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I Check if Periods Overlap

101 New Member
I have been given a project to create a room booking dbase and wish to search current records to validate a booking before I save it.

My booking records contains info like:-
Date StartTime EndTime RoomNo
10/10/2011 9AM 1PM 7
10/10/2011 1PM 4PM 7
10/10/2011 9AM 2PM 1
10/10/2011 3PM 5PM 1
12/10/2011 5PM 6PM 1

If I make a booking for Room 1 for (say) 10/10/2011 for 2PM to 4PM (say) I need to look in the tblBooking to check that the room is free on this date and time.

Would anyone be able to advise on this please.
Oct 18 '11
43 6657
101 New Member
Have sorted the strtRoomNo variable and this is OK. The script appears to be saying NOT Valid to all bookings except dates which are empty so it looks like it is either not comparing dates, room, time or it is not evaulating the variables.
Oct 18 '11 #11
101 New Member
Have entered a record for 21/10/2011 (room 2) for 6am - 8am and there is a booking starrting on this date for 9am. The script came back with VALID. It looks OK if we try a time before but some logic is wrong if we try after.

I also tried to book a room where there are no current bookings and it came back NOT Valid.

I will work on this tomorrow to see if I can understand what is happening?
Oct 18 '11 #12
101 New Member
I have been able to suss out what might be the problem. I got MsgBox to show me all variables on completion. It is not finding one of the fields in the table (this is BookEndTime).

This field is declared exacltly as BookTime and does contain data within the table yet the script finds everything except this one.

Cleary if the condition is testing this variable agianst a value it cannot do so and results might be illogical as a result I suspect.

Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As String
  2. Dim dteDate As Date
  3. Dim strRoomNo As String
  4. Dim dteStartTime As Date
  5. Dim dteEndTime As Date
  7. dteDate = Me!BookStartDate
  8. strRoomNo = Me!BookLocation
  9. dteStartTime = Me!BookTime
  10. dteEndTime = Me!BookEndTime
  12. strSQL = "BookStartDate = #" & dteDate & "# AND BookLocation = '" & strRoomNo & "' AND # " & _
  13. dteStartTime & "# BETWEEN BookTime AND BookEndTime OR #" & _
  14. dteEndTime & "# BETWEEN BookTime AND BookEndTime"
  16. 'MsgBox IIf(DCount("*", "tblRoomsBooking", strSQL) > 0, "Reservation NOT Valid", "Reservation Valid")
  17. 'MsgBox IIf(DCount("*", "tblRoomsBooking", strSQL) > 0, "Reservation NOT Valid", "Reservation Valid")
  18. MsgBox (BookEndTime & strSQL)
  20. End Sub
Oct 18 '11 #13
32,584 Recognized Expert Moderator MVP
Did you see post #5? You didn't respond in any way.

If you look again you will see that your logic is fundamentally flawed as it doesn't reliably find overlaps (but only a subset of them).
Oct 18 '11 #14
101 New Member
Hi Neopa

Sorry I had not seen your answer but am grateful for your information. My most critical problem however is to get the script working properly as I have established that it is not retrieving info from one of the table fields. IE the BookEndTime field.

This is strange as the field is declared the same as the BookTime field which is a Date/Time field set as Medium Time. The script as shown above extracts all required fields from my table Except the BookEndTime field. Once I have got this problem resolved I can look at your logic advise in more detail.
Have you any thoughts on why I cannot retrieve the field in question?
Oct 19 '11 #15
32,584 Recognized Expert Moderator MVP
That will be easier to help with if you post the SQL (I assume what you're referring to as the script) that you're expecting to return the values. See How to Debug SQL String for more on that.

However, going back over the posts, I see very little examples of your SELECT clause anywhere. The last version I see is in post #3 where the field [BookEndTime] is not included (which would explain its absence). I'd be happy to look in more detail if you post the latest version of your SQL string though.
Oct 19 '11 #16
8,834 Recognized Expert Expert
Not sure what you are doing, but I still say that my Logic is sound. I plugged in a Reservation for Room 2, on 10/21/2011, for 1:00 P.M. to 4:00 P.M., and the Return was that this 'is' a Valid Registration. See the Attachment for clarification:
Attached Files
File Type: zip Bookings_2.zip (14.0 KB, 130 views)
Oct 19 '11 #17
32,584 Recognized Expert Moderator MVP
What happens when you have a room booked for 13:00 - 16:00 and someone tries to book it for 09:00 - 17:30?

If that works correctly then I've missed something somewhere.
Oct 19 '11 #18
101 New Member
Hi ADezii

I think your is sound but my problem is that the srtSQL string is not returning a value for the BoookEndTime field in my table. All other fields are being returned except this one. Under such circustances the conditions cannot be evaulated as it can only compare the BookTime eliment.

I have looked at the table amd both BookTime and BookEndTime are declared as Date/Time Variables using Medium Time formatting. I have used MsgBox to show values of all fields within my table and the BookEndDate field is not displayed?
Oct 19 '11 #19
101 New Member
Hi agian NeoPa
Cant evaluate your request as I cannot get my strSQL statement to return a value for my BookEndDate with the table. All other fields are able to be read except the one mentioned?????? ?
Oct 19 '11 #20

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Ray Gardener | last post by:
I was wondering if anyone had tried implementing fuzzy logic set concepts in C++, because in FL, the concept of "type" or "class" is fuzzy; things belong (or are of) a given type only by degree. e.g., in a hypothetical fuzzy C++ language one could say: class pickle : public vegetable 0.2 { // pickle is not so much a vegetable as, say, onion is. };
by: Kurt Krueckeberg | last post by:
In the book C++ Gothcas, Gotcha #7 is an example of using boolean logic to simply code. My question follows this snippet from the book. "Do you have to count to eight when presented with the following?" int ctr = 0; for (int i =0; i < 8; ++i) { if (options & 1 << (8+i) ) if ( ctr++) { cerr << "too many options selected"; break;
by: Michelle S | last post by:
just a quick question about the logif for a program to add dollar and cents memebers from too different objects together public static Money operator + (Money m1, Money m2) { Money tempMoney = new Money(m1); tempMoney.dollars += m2.dollars; tempMoney.cents += m2.cents; if (tempMoney.cents > 99) { dollars += cents div 100;
by: Chris Kettenbach | last post by:
Hi I am designing an ASP.net app. Just wanted some opinions on code behind options. My idea is to have a code behind file that the controls will reference and have ascx files for the controls. Then have the aspx pages call the controls. Is this a good approach? I wanted to throw all my business logic in to the code behind file and then on the aspx pages that use the controls just refernce the ascx files. Is this the correct approach?...
by: bbcrock | last post by:
I have some modular code that is written for display purposes. It contains inline CSS code. I originally thought about moving all the inline code to a css file for use throughout the site- one css file with all the site's code. However this would hurt the code's portability throughout multiple sites. Does anyone know of a good article (or does anyone have strong opinions) about how to organize styles in modular code. The code in...
by: JoeC | last post by:
I am writing a game and I am having a challenge with my combat function. All I want to do is find out how to group pieces that are in the same space. There are two sides and all the units that are in the same space fight. I want to add up the attack factors and defending factors in the same space then figure out the odds so I can roll against an odds table. Basically each piece holds its own x and y loc. Here is what I have right...
by: Jordan | last post by:
All, I have a UI form calling a class object that contains a timer that routinely draws intensive information to the screen (~30 fps). The drawing is invoked on the main UI thread. I need the user to be able to interact with the UI while the drawing is happening (dynamically change drawing properties). Since the drawing is happening on the main UI thread, the UI form doesn't receive the user control events consistently (if at all).
by: galiorenye | last post by:
Hi, Given this code: A** ppA = new A*; A *pA = NULL; for(int i = 0; i < 10; ++i) { pA = ppA; //do something with pA
by: Israel Carr | last post by:
Thanks for anyone who takes the time to read this. If I posted to the wrong list, I apologize and you can disregard. I need help with a script to pull data from a postgres database. I'm ok with the database connection just not sure how to parse the data to get the results I need. I'm running Python 2.4.4. For what it's worth, once I can get my logic correct I'll be publishing the reports mentioned below via zope for web clients.
by: abueno | last post by:
Hi everybody, I am making a tic-tac-toe game where should be payable by two humans, the game should display all the current player turn....my problem is in the logic, when i set the first player=true; .....the output is right for the first player, but not for the second one, or when i set the value of the second player to true, i got the problem in the first player output ej function players_turn() { turn1=false; turn2=false; ...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.