我有一个日期可以是非连续的数组
$dates =
Array ( [0] => 17-06-2017 [1] => 18-06-2017 [2] => 22-06-2017 [3] => 23-06-2017 [4] => 24-06-2017 [5] => 30-06-2017 [6] => 09-07-2017 [7] => 10-07-2017 [8] => 11-07-2017 [9] => 12-07-2017 [10] => 13-07-2017 )
如果天数不连续且间隔小于8天,请添加缺失的范围
这是添加到数组
的日期19-06-2017 20-06-2017 21-06-2017 25-06-2017 26-06-2017 27-06-2017 28-06-2017 29-06-2017
从 01-07-2017 到 08-07-2017 的时间间隔为no,因为大于8天
如果间隔小于8天,则创建范围$ date_from,$ date_to
$arrayRanges = $this->createDateRangeArray($date_from, $date_to);
foreach ($arrayRanges as $key => $arrayRange) {
array_push($dates, date('Y-m-d', strtotime($arrayRange)));
}
public function createDateRangeArray($strDateFrom,$strDateTo) {
$aryRange=array();
$iDateFrom=mktime(1,0,0,substr($strDateFrom,5,2),substr($strDateFrom,8,2),substr($strDateFrom,0,4));
$iDateTo=mktime(1,0,0,substr($strDateTo,5,2),substr($strDateTo,8,2),substr($strDateTo,0,4));
if ($iDateTo>=$iDateFrom)
{
array_push($aryRange,date('d-m-Y',$iDateFrom)); // first entry
while ($iDateFrom<$iDateTo)
{
$iDateFrom+=86400; // add 24 hours
array_push($aryRange,date('d-m-Y',$iDateFrom));
}
}
return $aryRange;
}