I have an calendar event with StartDateTime and EndDateTime. These events are stored as records in database. I want to get all events for specific date. There are multiple scenarios that come to mind right away.
Given a specific date 12/01/2011, I want to get events which fall on 12/01/2011 (from 12:00:00 AM to 11:59:59 PM).
So I need to select:
-
Events whose StartDateTime and EndDateTime falls into range of 12/01/2011 12:00:00 AM and 12/01/2011 11:59:00 PM
-
Events that span onto next day. That is StartDateTime is on 12/01/2011 before 11:59:59 PM but EndDateTime is sometime in future
-
Events whose EndDateTime is on 12/01/2011 but before 11:59:59 PM and whose StartDateTime is before 12/01/2011 12:00:00 AM
-
Events that span multiple days. That is StartDateTime is before 12/01/2011 12:00:00 AM and EndDateTime is after 12/01/2011 11:59:59 PM
I might be missing other scenarios. I have a feeling this is not an original problem and there are methods out there that do exactly what I need. Is there a standard way to select these events?
I think your 4 cases break down to a single statement (pseudocode)