这是规则:
以下是一个例子:
天数的计算将是:
过去200天的计算方法如下:
总计 920天
任何帮助都将受到赞赏并提前感谢。
答案 0 :(得分:0)
感谢您的帮助,这就是我最终使用的内容:
$iDate = Carbon::createFromDate(2010, 2, 2);
$eDate = Carbon::createFromDate(2012, 8, 21);
$dateDiff = date_diff($iDate, $eDate);
$date = 0;
$date += $dateDiff->y * 360;
$date += $dateDiff->m * 30;
$date += $dateDiff->d + 1; // Need to add one more day
dd($date); // Outputs 920
这是使用包含Carbon包的Laravel。
答案 1 :(得分:0)
//2/2/10 to 2/1/11 = 360 days
$date_1 = "2/2/10";
$date_2 = "2/1/11";
$differenceFormat = "%a";
$diff = dateDifference($date_1 , $date_2 , $differenceFormat) ;
echo "<br/>";
echo "$date_1 to $date_2 = $diff days";
//2/2/11 to 2/1/12 = 360 days
$date_1 = "2/2/11";
$date_2 = "2/1/12";
$differenceFormat = "%a";
$diff = dateDifference($date_1 , $date_2 , $differenceFormat) ;
echo "<br/>";
echo "$date_1 to $date_2 = $diff days";
//2/2/12 to 8/21/12 = 200 days
$date_1 = "2/2/12";
$date_2 = "8/21/12";
$differenceFormat = "%a";
$diff = dateDifference($date_1 , $date_2 , $differenceFormat) ;
echo "<br/>";
echo "$date_1 to $date_2 = $diff days";
//final
$date_1 = "2/2/10";
$date_2 = "8/21/12";
$differenceFormat = "%a";
$diff = dateDifference($date_1 , $date_2 , $differenceFormat) ;
echo "<br/>";
echo "$date_1 to $date_2 = $diff days";
function dateDifference($date_1 , $date_2 , $differenceFormat = '%a' )
{
$datetime1 = date_create($date_1);
$datetime2 = date_create($date_2);
$interval = date_diff($datetime1, $datetime2);
return $interval->format($differenceFormat);
}