-1
Hello, friends. I have a code where I calculate the difference in days between two dates. I need to pass the variables to the object instance, but it only works if I put the string manually.
(1) This way below works:
$origin = new DateTime('2017-03-03');
$target = new DateTime('2017-04-06');
$interval = $origin->diff($target);
echo $interval->format('%R%a days');
(2) But this way below, which is what I need, does not work:
$origin = new DateTime($dataInicio);
$target = new DateTime($dataFim);
$interval = $origin->diff($target);
echo $interval->format('%R%a days');
Froma (1) returns me 34 days, but the form (2), when I pass the parameters with the same dates of (1), gives a value +209 days, gives 6 months and 26 days . How would I solve this? Can someone help me?
Two things: 1) their variables are actually strings? 2) If yes to the above question, their format corresponds to the necessary?
– ricardobarantini