I have a tbl_availability that determines when a resource is available. The table structure is:
id - running id
startdate - when this availability starts
enddate - when this availability ends
dayofweek - weekday of availability
fromtime - start time
totime - end time
There can be multiple records for the same dayofweek, for example one record for Sundays 1000-1200 and another record for Sundays 1300-1400.
I am trying to figure out how to get two things:
- Check when entering a new record that there is no conflict (overlap) with an existing record
- Given a startdate and enddate, find all of the available periods that apply.
To determine if there's a conflict this query will return any overlapping time ranges:
The first part of the where clause checks for anything that overlaps the start time. The second part check for anything that overlaps the end time. The third part check for anything within the range.
To check for available time ranges for a specified duration use this:
I haven't tested these queries, so there may have to be some tweaking going on here.