[英]php date difference & integer calculate
我在遵循代碼方面確實存在很多問題。 首先,我嘗試獲取兩個日期之間的天數,然后嘗試與某個整數相乘。 但是,它沒有成倍增加。 如何獲得正確答案?
幫幫我
function GetTotalDay($D1, $D2)
{
//$str = "19-04-2016";
$str = strtotime($D2) - (strtotime($D1));
echo (int)floor($str/3600/24);
}
$C1=GetTotalDay("01/01-2016", "03-01-2016");
$C2=12;
echo $C1 * $C2;
檢查此更正的代碼
function GetTotalDay($D1, $D2) {
$str = strtotime($D2) - (strtotime($D1));
return (int)floor($str/3600/24);
}
$C1 = GetTotalDay("01-01-2016", "03-01-2016");
$C2 = 12;
echo $C1 * $C2;
您有2個錯誤。
1)您使用錯誤的日期格式
2)您沒有退貨功能
<?php
function GetTotalDay($D1, $D2)
{
//$str = "19-04-2016";
$str = strtotime($D2) - (strtotime($D1));
return (int)floor($str/3600/24);
}
$C1=GetTotalDay("01-01-2016", "03-01-2016");
$C2=12;
echo $C1 * $C2;
?>
結果:
24
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.