In this article, you will learn the PHP date_interval_for() function to format the interval. It is an alias of the DateInterval::format() function.
What is the syntax of the date_interval_format() function in PHP?
DateInterval::format(format)
Parameters | Details |
---|---|
format | Specify the format – Required |
Examples of the date_interval_format() function
Example 1. In the following example, we simply calculate the difference between two dates.
<?php
$date_1=date_create("2021-01-01");
$date_2=date_create("2017-04-10");
$diff=date_diff($date_1,$date_2);
echo $diff->format("Difference is: %a.");
?>