Alfonso, that whole already exists in your object . You just have to get the value inside the object if that's what you're interested in. So you save yourself having to apply output formats and then reconvert again.
If you make a var_dump($interval)
you can see that in effect your object has a property days
, which is of type int
, that is, the data and type you need:
object(DateInterval)#3 (15) {
["y"]=>
int(0)
["m"]=>
int(11)
["d"]=>
int(26)
["h"]=>
int(0)
["i"]=>
int(0)
["s"]=>
int(0)
["weekday"]=>
int(0)
["weekday_behavior"]=>
int(0)
["first_last_day_of"]=>
int(0)
["invert"]=>
int(0)
["days"]=>
int(361)
["special_type"]=>
int(0)
["special_amount"]=>
int(0)
["have_weekday_relative"]=>
int(0)
["have_special_relative"]=>
int(0)
}
That means that you can get the value of that property as it is through your object, which for that you have:
$intDiff=$interval->days;
Like this, you can get any of the other properties you need, without having to resort to other types of manipulations. That is one of the great advantages of working with objects.
Test:
If we test what type is the variable that we just created, taking it from the object directly:
var_dump($intDiff);
Exit:
We will see that it is a variable of type int
. That is, just what you are looking for.
int(361)
Doing this saves you two steps:
Having to apply format: $strDiff= $interval->format('%r%a');
To then have to convert it to whole.