PHP DateInterval class
The PHP DateInterval class represents a date interval. A date interval stores either a fixed amount of time (in years, months, days, hours etc) or a relative time string in the format that DateTime's constructor supports.
More specifically, the information in an object of the DateInterval class is an instruction to get from one date/time to another date/time. This process is not always reversible.
A common way to create a DateInterval object is by calculating the difference between two date/time objects through DateTimeInterface::diff() function.
Class synopsis
class DateInterval { //Properties public int $y; public int $m; public int $d; public int $h; public int $i; public int $s; public float $f; public int $invert; public mixed $days; //Methods public __construct(string $duration) public static createFromDateString(string $datetime): DateInterval|false public format(string $format): string }
Properties
y | Number of years. |
m | Number of months. |
d | Number of days. |
h | Number of hours. |
i | Number of minutes. |
s | Number of seconds. |
f | Number of microseconds, as a fraction of a second. |
invert | 1 if the interval represents a negative time period, otherwise 0. |
days | If the DateInterval object was created by DateTime::diff(), then this is the total number of days between the start and end dates. Otherwise, days will be false. |
❮ PHP Date and Time Reference