inserting into valid date slot in database
hihi..
i am trying to insert a start_date and an end_date of an event into the database. Assume that i have already inserted a number of events into the database and there is no crash of event date. Initially i have based on the end date of the last event to check if the schedule has crashed into the exiting event in the database which teh date might have been taken up by an exiting event.
For example,
1. Event 1 fall on 02-FEB-05 to 02-APR-05
******************FREE SLOT*************************
2. Event 2 fall on 02-AUG-05 to 02-OCT-05
3. Event 3 fall on 02-NOV-05 to 02-DEC-05
Question,
1. if i have an another event fall on 02-MAY-05 to 02-JUN-05 which i need to insert into the database, how can i validated that there is no conflict/crash into other exiting event? how can i do to avoid the crash?
???
ocw
Re: inserting into valid date slot in database
Assuming that your date fields are called Start_date and End_date, and your input dates are stored in variables dStart and dEnd you could use SQL something like this:
VB Code:
sSQL = "SELECT count(*) " _
& "FROM [b]tablename[/b] " _
& "WHERE '" & dStart & "' BETWEEN Start_date AND End_date " _
& "OR '" & dEnd & "' BETWEEN Start_date AND End_date "
If the value returned by this isn't 0 then there is a clash, and the new record should not be allowed (instead of a Count you could return the fields, so that you can provide 'correct' dates).