Php/docs/class.dateinterval
(PHP 5 >= 5.3.0, PHP 7)
Introduction
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().
Class synopsis
DateInterval {
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
public format
( string $format
) : string
}
Properties
yNumber of years.
mNumber of months.
dNumber of days.
hNumber of hours.
iNumber of minutes.
sNumber of seconds.
fNumber of microseconds, as a fraction of a second.
invertIs
1if the interval represents a negative time period and0otherwise. See DateInterval::format().daysIf the DateInterval object was created by DateTime::diff(), then this is the total number of days between the start and end dates. Otherwise,
dayswill beFALSE.Before PHP 5.4.20/5.5.4 instead of
FALSEyou will receive -99999 upon accessing the property.
Changelog
| Version | Description |
|---|---|
| 7.1.0 | The f property was added.
|
Table of Contents
- DateInterval::__construct — Creates a new DateInterval object
- DateInterval::createFromDateString — Sets up a DateInterval from the relative parts of the string
- DateInterval::format — Formats the interval
/* Properties */