// Returns an array of days that have bookings for a given property_id within month and year function get_bookings_for_calendar($property_id, $month, $year) { $query = $this->db->getwhere('bookings', array('property_id' => $property_id)); // Collect days for each period $booked_days = array(); foreach ($query->result_array() as $row){ // Get date as seperate days, months, years $start_date_split = explode("-", $row["start_date"]); $start_day = (int) $start_date_split[2]; $start_month = (int) $start_date_split[1]; $start_year = (int) $start_date_split[0]; $end_date_split = explode("-", $row["end_date"]); $end_day = (int) $end_date_split[2]; $end_month = (int) $end_date_split[1]; $end_year = (int) $end_date_split[0]; $fromDate = mktime(0, 0, 0, $start_month, $start_day, $start_year); $toDate = mktime(0, 0, 0, $end_month, $end_day, $end_year); // Loop through dates and add any ones that fall // within current month/year in booked_days array for ($myDate = $fromDate; $myDate <= $toDate; $myDate = strtotime("+1 day", $myDate)) { // Do some funky logic to figure out if this day // needs to be added to booked days if (something) $booked_days = $booked_days + array($n => "#1a99d1"); // For debugging purposes $printable = strftime("%d-%m-%Y %H:%M:%S", $myDate); echo $printable; } } return $booked_days; }