function get_occurs_within_where_clause($table_name, $rel_table, $start_ts_obj, $end_ts_obj, $field_name = 'date_start', $view) { global $timedate; $dtUtilArr = array(); switch ($view) { case 'month': $start_ts = $start_ts_obj->get_first_day_of_this_month(); $end_ts = $end_ts_obj->get_first_day_of_next_month(); break; default: // Date for the past 5 days as that is the maximum duration of a single activity $dtUtilArr['ts'] = $start_ts_obj->ts - 86400 * 5; $start_ts = new DateTimeUtil($dtUtilArr, false); // Date for the next 5 days as that is the maximum duration of a single activity $dtUtilArr['ts'] = $end_ts_obj->ts + 86400 * 5; $end_ts = new DateTimeUtil($dtUtilArr, false); break; } $start_mysql_date = explode('-', $start_ts->get_mysql_date()); $start_mysql_date_time = explode(' ', $timedate->handle_offset(date($GLOBALS['timedate']->get_db_date_time_format(), $start_ts->ts), $timedate->dbDayFormat, true)); $end_mysql_date = explode('-', $end_ts->get_mysql_date()); $end_mysql_date_time = explode(' ', $timedate->handle_offset(date($GLOBALS['timedate']->get_db_date_time_format(), $end_ts->ts), $timedate->dbDayFormat, true)); $where = "(" . db_convert($table_name . '.' . $field_name, 'date_format', array("'%Y-%m-%d'"), array("'YYYY-MM-DD'")) . " >= '{$start_mysql_date_time[0]}' AND "; $where .= db_convert($table_name . '.' . $field_name, 'date_format', array("'%Y-%m-%d'"), array("'YYYY-MM-DD'")) . " <= '{$end_mysql_date_time[0]}')"; if ($rel_table != '') { $where .= ' AND ' . $rel_table . '.accept_status != \'decline\''; } return $where; }