Overview:
I have a SQL database table where each row (event) contains a start and end date formatted as a timestamp.
Target:
Show events for a given week, these include events that start and end within that week, but may also take place within that week (their start/end dates may be within that week, or they may be before that week begins and ends after that week). Example of expected result:
I've tried using a BETWEEN query and a query using start > {$week_start} AND end < {$week_end}, but neither method takes into account "overlapping" dates.
Question: Is it possible to write a single query that covers all these cases?
BTW, if there is a better solution, I would accept using a date format other than timestamp.
P粉2223201762023-07-22 00:35:31
The logic you are looking for is:
start <= {$week_end} AND end >= {$week_start}