PHP date_interval_format() Function
Example
Calculate the interval between two dates, then format the 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.");
?>
Try it Yourself »
Definition and Usage
The date_interval_format() function is an alias of DateInterval::format().
The DateInterval::format() function is used to format the interval.
Syntax
DateInterval::format(format)
Parameter Values
Parameter | Description |
---|---|
format | Required. Specifies the format. The following characters can be used in the format parameter string:
Note: Each format character must be prefixed by a % sign! |
Technical Details
Return Value: | Returns the formatted interval |
---|---|
PHP Version: | 5.3+ |
PHP Changelog: | PHP 7.1: Added the F and f parameters |
❮ PHP Date/Time Reference