function timeBetween($start, $end){
$d_s = strtotime(date('Y-m', $start));
$d_e = strtotime(date('Y-m', $end));
$num = 1;
$dates = array();
while ($start<=$end){
if($d_s == $d_e){
$dates[] = array(
'time_start' => date('Y-m-d',$start),
'time_end' => date('Y-m-d',$end),
);
break;
}else{
if($num == 1){
$dates[] = array(
'time_start' => date('Y-m-d',$start),
'time_end' => date('Y-m-t',$start),
);
}else{
$dates[] = array(
'time_start' => date('Y-m' . '-01',$start),
'time_end' => date('Y-m-t',$start),
);
}
$start = strtotime('+1 month',$start);
}
$num ++;
}
$pop_ele = array_pop($dates);
$pop_ele['time_end'] = date('Y-m-d',$end);
array_push($dates, $pop_ele);
return $dates;
}
測試:
var_dump(timeBetween(strtotime('2005-02-01'),strtotime('2005-02-05')));