php/** * 返回兩個時間相差的天數 * @param string $starttime 開始日期 * @param string $endtime 結束日期 * @return [type] [description] */ private function _days($starttime='', $endtime='') { $start = new DateTime($starttime); $end = new DateTime($endtime); $interval = $start->diff($end); return $interval->format('%a'); }
php/** * 遍歷日期 * @param string $starttime 開始日期 * @param string $endtime 結束日期 * @return [type] [description] */ private function _dateArray($starttime='', $endtime='') { // 按每小時遍歷,因此每次增長3600秒 for ($start = strtotime($starttime); $start <= strtotime($endtime); $start += (3600*24)) { $dateArray[] = date('Y-m-d', $start); } return $dateArray; }