Question

I have several task:

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

With my algorithm is

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

But is that enough? I mean the logical way it seem only subtraction, after the execution date is added by the duration. But in details, seems that variable for the $duration may be difference. The above case is only for month duration. How about when it is Year duration? and how about days duration?

Ya, how to do it in Php & VB.net? Both have its own language.

Was it helpful?

Solution

You can use something like this to get the differnce between two dates:

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

now you have 2 options:

Use the format option:

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

Example output:

2 Days

Or use the array with diff:

print_r($interval) ;

Example output of the array:

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
)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top