Here is the sample code
$c = new DateTime();
$o = clone $c;
$o->modify('-60 days');
$diff = $c->diff($o);
$diff2 = $c->diff($o, TRUE);
var_dump($diff, $diff2);
which outputs
object(DateInterval)#3 (8) {
["y"]=> int(0), ["m"]=> int(1), ["d"]=> int(29), ["h"]=> int(0), ["i"]=> int(0),
["s"]=> int(0), ["invert"]=> int(1), ["days"]=> int(60)
}
object(DateInterval)#4 (8) {
["y"]=> int(0), ["m"]=> int(1), ["d"]=> int(29), ["h"]=> int(0), ["i"]=> int(0),
["s"]=> int(0), ["invert"]=> int(0), ["days"]=> int(60)
}
as I see, only the “invert” property changes. What does this mean?
The absolute property will return the absolute difference between two DateTime objects. This will change the result to positive when a negative difference is returned.