Q:

I need to check multiple date ranges to see if they have a same day more than 3 times

Okay, so I have a start datetime and an end datetime for multiple items. I need to find out if there are more than 3 items that are within the same datetime as each other. I just can't wrap my head around this one, I can get the days of each individual item into an array using this function
function getDatesBetween2Dates($startTime, $endTime) {
$day = 86400;
$format = 'm/d/y g:i A';
$startTime = strtotime($startTime);
$endTime = strtotime($endTime);
$numDays = round(($endTime - $startTime) / $day) + 1;
$days = array();
for ($i = 0; $i < $numDays; $i++) {
    $days[] = date($format, ($startTime + ($i * $day)));
}
return $days;
}

The problem is, it only get the first time and just adds a full day to every day afterward. it doesn't take into account for the last days time. I just can't think of an efficient way to do this.
Just to clarify, let me give you an example. I have 5 items in my table, they each have a datetime range.. start and end. I need to check if 4 or more of those items have any days in their date range that are the same. Can anyone point me in the right direction? Thanks.

A:

Change for ($i = 0; $i < $numDays; $i++) { to for ($i = 0; $i <= $numDays; $i++) { to get all dates in the range, including the last date.
Unfortunately you're going about this the wrong way. Here's some pseudocode of how I would do it:
Iterate through the list of date ranges
    Log the earliest start date
    Log the last end date

Iterate through all dates between the earliest start date and the last end date
    Iterate through the list of date ranges, to determine how many date ranges contain the current date
        If more than three date ranges contain the current date, then store it in an array of conflicting dates

I don't believe this is the most efficient way, but unless you're dealing with huge date ranges or quite a large number of dates, it will be relatively fast.

