Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Fill in missing events



2:51 am on Feb 5, 2014 (gmt 0)

5+ Year Member

I have a database of events (which I pull regularly from an API). Each event has a begin and end time (format YYYY-MM-DD HH:MM:SS). I'm using PHP to displaying these events on a HTML table calendar. So far no problem.

I need to show an "available" message between events. For example, if there is an event from 06:12 to 09:55, I need the calendar to display a message saying "available" from 00:00 to 06:12, and again from 09:55 to 23:59. There could (and usually will be) multiple events and multiple availability periods each day.

What's the best approach here? My puzzler has puzzled itself sore.


4:41 am on Feb 5, 2014 (gmt 0)

WebmasterWorld Senior Member tangor is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

I populate such calendars with all spots "available" EXCEPT for the spots that are specifically scheduled (ie, overwrites the "avaiable" with the specific sheduled event). Saves time and is accurate in that all NOT scheduled times are available.


8:32 am on Feb 5, 2014 (gmt 0)

WebmasterWorld Senior Member swa66 is a WebmasterWorld Top Contributor of All Time 10+ Year Member

For the period you're going to display (I've no idea which, but that one)
Create one available "event" from begin to end is a one item list
Loop over the results of the "busy" events in your database
For every busy event, you add, to your list, taking care to deal with all possible cases and edge cases.
Once that's done: take care to remove any zero or 1 sec length (or wherever you set your threshold) available slots, and finally split up the available slots that cross a date boundary (as that seems a requirement from your post).

In the end you'll have a lot of code I'm afraid due to the edge cases.

For making your list: an array seems appropriate.

Featured Threads

Hot Threads This Week

Hot Threads This Month