2017-01-11 4 views
0

Carbon PHP를 사용하려고하는데, 새로운 점은 진행 방법을 잘 모릅니다. 한 달 동안의 일 수를 얻고 싶습니다. 따라서 Carbon 인스턴스를 만들어 그 달의 첫날을 얻습니다. 한 달 추가하고 diffInDays 함께 차이를 가져 오려고하지만 그것은 나를 0 반환합니다. 많은 것들을 시도했지만이 문제를 해결할 수 없습니다. 너희들 생각이 있니?DiffInDays in Carbon php

다음은 코드입니다.

$month = intval($_GET['month'], 10); 
$year = intval($_GET['year'], 10); 


$monthToEvaluate = Carbon::create($year, $month, 1, 0, 0); //It returns a Carbon Instance with the correct date 
$monthAfter = $monthToEvaluate->addMonth(); //It returns a Carbon Instance with the correct date too 

echo $monthAfter->diffInDays($monthToEvaluate, false); //var_dump of this returns int(0) 
+0

'$ monthToEvaluate-> addMonth()에서,'그렇지 불변 ... $ monthToEvaluate''그래서'$ monthToEvaluate을 수정 '와'$ monthAfter'는 같을 것입니다 –

답변

0

참조,이 방법을 시도 더 http://carbon.nesbot.com/docs/

$monthToEvaluate = Carbon::create($year, $month, 1, 0, 0); 
echo $monthToEvaluate->diffInDays($monthToEvaluate->copy()->addMonth());