I have an Event table that specifies a date range with start_date
and end_date
fields. I have another date range, specified in code, that defines the
You could write your condition like this:
start_date <= week_end AND end_date >= week_start
Edit: this assumes start_date <= end_date and week_start <= week_end ( are properly ordered) and gives you the best performance on most db implementations due to not using OR (which on some databases may create performance issues)
Edit2: this solution also solves the problem of events that begin before the interval and end after the interval.