如何获取工期添加日期后工期的百分比


How to get percentage of duration after date added by Duration?

我有几个任务:

$submitted = "Friday, April 11, 2014 02:55 PM"
$duration = "3 Month"
$execution = "Friday, April 13, 2014 02:55 PM"

我的算法是

$percentage = calculate ($execution+$duration) - $submitted 
$percentage = $percentage divided by 100%.

但这够了吗?我的意思是,它看起来只是减法,在执行日期加上持续时间之后。但在细节上,似乎美元持续时间的变量可能有所不同。上述情况仅适用于持续时间的月份。年持续时间如何?天的持续时间如何?

呀,怎么在Php&VB.net?两者都有自己的语言。

您可以使用类似的方法来获得两个日期之间的差异:

$datetime1 = new DateTime('Friday, April 11, 2014 02:55 PM');
$datetime2 = new DateTime('Sunday, April 13, 2014 02:55 PM');
$interval = $datetime1->diff($datetime2);

现在您有两个选项:

使用格式选项:

echo $interval->format('%d Days');

示例输出:

2 Days

或者使用diff:的数组

print_r($interval) ;

阵列输出示例:

DateInterval Object
(
    [y] => 0
    [m] => 0
    [d] => 2
    [h] => 0
    [i] => 0
    [s] => 0
    [weekday] => 0
    [weekday_behavior] => 0
    [first_last_day_of] => 0
    [invert] => 0
    [days] => 2
    [special_type] => 0
    [special_amount] => 0
    [have_weekday_relative] => 0
    [have_special_relative] => 0
)