でグループ化されたタイムスタンプ値iはPHPは数ヶ月
$time1 = 1492894800 //23/04/2017
$time2 = 1503521999 //23/08/2017
は私が
get timestamp with rangess between months preserving first and last month of $time1 and $time2 such that i should have
1 23/04/2017 to 30/04/2017
2 01/05/2017 - 31/05/2017
....... //continue full months and lastly
01/08/2017 - 23/08/2017
私が試しているように数ヶ月ごとにグループ化されたタイムスタンプを取得したいと思い持っていると仮定し得る
$timearrays = $this->getMontTimestampRanges($time1, $time2);
public function getMontTimestampRanges($ts1, $ts2){
$start = (new DateTime(date("Y-m-d", $ts1)));
$end = (new DateTime(date("Y-m-d", $ts2)));
$interval = DateInterval::createFromDateString('1 day');
$period = new DatePeriod($start, $interval, $end);
$timestamps = [];
foreach ($period as $dt) {
//am stuck here on how to group based on the months
..push to array
}
return $timestamps;
}
最終的な配列は次のような形になります:
$timestamps = [
0=>["from":, "to": ] //first month(april)
1=>[ ] //second month may
]
どうすればよいですか?
日付が例えば接近しているとき、これは失敗します。5月31日と6月1日の期間の配列は、一つの値だけ、ともしたときのタイムゾーンです。 –