<?php
$january = new DateTime('2010-01-01');
$february = new DateTime('2010-02-01');
$interval = $february->diff($january);
// %a will output the total number of days.
echo $interval->format('%a total days')."\n";
// While %d will only output the number of days not already covered by the
// month.
echo $interval->format('%m month, %d days');
The above example will output:
31 total days
1 month, 0 days
Notes
Note:
The DateInterval::format() method does not
recalculate carry over points in time strings nor in date segments. This
is expected because it is not possible to overflow values like "32 days"
which could be interpreted as anything from "1 month and 4 days"
to "1 month and 1 day".
See Also
DateTime::diff() - Returns the difference between two DateTime objects