1
日付範囲内のすべての金曜日を取得する方法:私は2つの日付の間のすべての金曜日を取得するには、この機能を使用していた炭素
public function getFridaysInRange($dateFromString, $dateToString)
{
$dateFrom = new \DateTime($dateFromString);
$dateTo = new \DateTime($dateToString);
$dates = [];
if ($dateFrom > $dateTo) {
return $dates;
}
if (1 != $dateFrom->format('N')) {
$dateFrom->modify('next friday');
}
while ($dateFrom <= $dateTo) {
$dates[] = $dateFrom->format('Y-m-d');
$dateFrom->modify('+1 week');
}
return $dates;
}
$this->getFridaysInRange('2017-01-01','2017-01-30');
結果:
array:4 [▼
0 => "2017-01-06"
1 => "2017-01-13"
2 => "2017-01-20"
3 => "2017-01-27"
]
は
carbon
で任意の関数などがあります上記?
ない:http://stackoverflow.com/questions/ 7061802/php-function-for-get-all-mondays-within-date-range –
とにかくhttp://carbon.nesbot.com/docs/を見ているあなたのような単一の機能があるとは思わない: ) –