<?php /** * @param sdate 开始日期 * @param edate 结束日期 */ function get_months($sdate, $edate) { $range_arr = array(); do { $monthinfo = get_monthinfo_by_date($sdate); $end_day = $monthinfo['month_end_day']; $start = substr_date($monthinfo['month_start_day']); $end = substr_date($monthinfo['month_end_day']); $range = "{$start} ~ {$end}"; $range_arr[] = $range; $sdate = date('Y-m-d', strtotime($sdate.'+1 month')); }while($end_day < $edate); return $range_arr; } /** * 截取日期中的月份和日 * @param string $date * @return string $date */ function substr_date($date) { if ( ! $date) return FALSE; return date('m-d', strtotime($date)); } /** * 根据指定日期获取所在月的起始时间和结束时间 */ function get_monthinfo_by_date($date){ $ret = array(); $timestamp = strtotime($date); $mdays = date('t', $timestamp); return array( 'month_start_day' => date('Y-m-1', $timestamp), 'month_end_day' => date('Y-m-'.$mdays, $timestamp) ); } ?>
本文结束