2017-01-11 10 views
0

私はCarbon PHPを使用しようとしています。私はそれを初めて知っているので、進める方法がわかりません。私は1ヶ月間の日数を取得したいので、Carbonインスタンスを作成してその月の1日目を取得します。私はそれに月を追加し、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());