Compute the interval between two dates, and then format the resulting interval.
<?php $date1=date_create(“2013-01-01”); $date2=date_create(“2013-02-10”); $diff=date_diff($date1,$date2); // %a outputs the total number of days echo $diff->format(“Total number of days: %a.”); ?> |
The date_interval_format() function is an alias for DateInterval::format().
The DateInterval::format() method is used to format the interval.
DateInterval::format(format) |
Parameter |
Description |
format |
Required. Specifies the format using the following characters in the format string:
Note: Each format character must be prefixed by a % sign. |
Return Value: |
Returns the interval formatted according to the specified format. |
PHP Version: |
5.3+ |
PHP Changelog: |
In PHP 7.1, the |