Quote:
Originally posted by srikb
I completed this using jsp code and it works great. I really appreciate all your help.
|
Sample code for an appointment that would start at 13:00 and end at: 13:30. If the last select returns a row, it mean you cannot schedule the appointment..
create table horaire (app_start datetime,
app_end datetime,
name varchar(30)) type = Myisam;
insert into horaire (app_start, app_end, name) values
('2003-10-09 13:00:00', '2003-10-09 15:00:00', 'Joe First'),
('2003-10-09 17:00:00', '2003-10-09 19:00:00', 'Joe Second'),
('2003-10-09 19:00:00', '2003-10-09 20:00:00', 'Joe Third'),
('2003-10-09 20:00:00', '2003-10-09 23:00:00', 'Joe Fourth'),
('2003-10-10 07:00:00', '2003-10-10 09:00:00', 'Joe Fifth'),
('2003-10-10 13:00:00', '2003-10-10 15:00:00', 'Joe Sixth'),
('2003-10-13 13:00:00', '2003-10-13 15:00:00', 'Joe Seventh');
select * from horaire;
select * from horaire
where
('2003-10-13 13:00:00' = app_start) or /* Starts at the same time */
('2003-10-13 13:30:00' = end_start) or /* Ends at the same time */
('2003-10-13 13:00:00' < app_start and '2003-10-13 13:30:00' > end_start) or /* Starts Before and Ends After (stradles existing appt) */
('2003-10-13 13:00:00' < app_start and ('2003-10-13 13:30:00' between app_start and end_start)) OR /* Starts Before and Ends During (interrupts) */
('2003-10-13 13:00:00' between app_start and app_end) and ('2003-10-13 13:30:00' between app_start and end_start)) OR /* Starts During and Ends During (contained) */
(('2003-10-13 13:00:00' between app_start and app_end) and ('2003-10-13 13:30:00' > end_start)) /* Starts During and Ends After (interrupts) */
Hope this helps.
ALWAYS LET THE SERVER DO THE WORK!!!