If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Select Query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-31-09, 08:57
zed420 zed420 is offline
Registered User
 
Join Date: Aug 2009
Posts: 3
Select Query

Hi All
I've managed to get somewhere with the query below with some help but it has a small problem after rigorous testing I found there is a small glitch e.g. Let’s say if I book from 10:00 to 13:00 and someone tries to book it from 08:00 to 21:00 (all day) IT WILL BOOK, meaning it will over lap. I have tried to sort it but failing miserably, anyone with any thoughts
Thanks
Zed
Code:
SELECT b_id, COUNT(*) AS Cnt 
	FROM booking 
	WHERE request_date='$request_date' AND 
	( 
   ($s_time >= s_time AND $s_time < e_time) OR 
   ($e_time > s_time AND $e_time <= e_time) 
	) 
	GROUP BY b_id
Reply With Quote
  #2 (permalink)  
Old 09-01-09, 07:17
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
see similar post: Absences between a date range...

Code:
SELECT COUNT(*) AS Cnt 
  FROM booking 
 WHERE request_date = '$request_date' 
   AND $e_time > s_time 
   AND $s_time < e_time
when Cnt is > 0, that means there is already some booking that overlaps your $s_time::$e_time range

hint: do not split your dates and times into separate columns -- use a single DATETIME column

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 09-01-09, 14:07
zed420 zed420 is offline
Registered User
 
Join Date: Aug 2009
Posts: 3
Thank you sir I saw your post of timeline in a different forum and managed to sort it. That was a great help it's been a week I've been at this query.

Thanks
Zed
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On