我有几项任务:
$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?两者都有自己的语言。
答案 0 :(得分:1)
你可以使用这样的东西来获得两个日期之间的差异:
$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
)