The method format()
uses different modifiers that allow the text to be replaced in them depending on the value you indicate them.
What does this mean?
On the line where you do:
echo $interval->format('%R%a días');
You are making the function format
replace % R and _% a% with the following values (according to the PHP Documentation ) :
R Sign "-" when it is negative, "+" when it is positive
a Total number of days as a result of an operation with DateTime :: diff (), or otherwise (unknown)
What is missing in the format
are the modifiers, which will return the difference in hours, minutes and seconds, (according to PHP Documentation ) :
H Hours, numeric, at least 2 digits starting with 0
I Minutes, numeric, at least 2 digits starting with 0
S Seconds, numeric, at least 2 digits starting with 0
Leaving your code like this:
<?php
$datetime1 = date_create('2009-10-11 19:10:01');
$datetime2 = date_create('2009-10-13 20:11:05');
$interval = date_diff($datetime1, $datetime2);
echo $interval->format('%R%a días %H horas %I minutos %S segundos');
?>
Result
+2 days 01 hours 01 minutes 04 seconds