DatePeriod::__constructCreates a new DatePeriod object
&reftitle.description;
publicDatePeriod::__constructDateTimeInterfacestartDateIntervalintervalintrecurrencesintoptions0publicDatePeriod::__constructDateTimeInterfacestartDateIntervalintervalDateTimeInterfaceendintoptions0publicDatePeriod::__constructstringisostrintoptions0
This variant of the constructor has been deprecated, use
DatePeriod::createFromISO8601String instead.
Creates a new DatePeriod object.
DatePeriod objects can be used as an iterator to
generate a number of DateTimeImmutable or
DateTime object from a start
date, a interval, and an end
date or the number of recurrences.
The class of returned objects is equivalent to the
DateTimeImmutable or DateTime
ancestor class of the start object.
&reftitle.parameters;
start
The start date of the period. Included by default in the result set.
interval
The interval between recurrences within the period.
recurrences
The number of recurrences. The number of returned results is
one higher than this, as the start date is included in the result set
by default. Must be greater than 0.
end
The end date of the period. Excluded by default from the result set.
isostr
A subset of the ISO 8601 repeating
interval specification.
Examples of some ISO 8601 interval specification features that PHP does
not support are:
zero occurrences (R0/)
time offsets other than UTC (Z), such as +02:00.
options
A bit field which can be used to control certain behaviour with start-
and end- dates.
With DatePeriod::EXCLUDE_START_DATE you
exclude the start date from the set of recurring dates within the
period.
With DatePeriod::INCLUDE_END_DATE you
include the end date in the set of recurring dates within the
period.
&reftitle.errors;
Throws an DateMalformedPeriodStringException when
the isostr cannot be parsed as a valid ISO 8601
period. Prior to PHP 8.3, this was
Exception.
&reftitle.changelog;
&Version;&Description;8.3.0
Now throws
DateMalformedPeriodStringException
instead of Exception.
8.2.0
The DatePeriod::INCLUDE_END_DATE constant has been added.
7.2.19, 7.3.6, 7.4.0recurrences must be greater than 0 now.
&reftitle.examples;
DatePeriod example
format('Y-m-d')."\n";
}
?>
]]>
&example.outputs;
DatePeriod example with DatePeriod::EXCLUDE_START_DATE
format('Y-m-d')."\n";
}
?>
]]>
&example.outputs;
DatePeriod example showing all last Thursdays in a year
format('l Y-m-d'), "\n";
}
?>
]]>
&example.outputs;
&reftitle.notes;
Unbound numbers of repetitions as specified by ISO 8601 section 4.5
"Recurring time interval" are not supported, i.e. neither passing
"R/..." as isostr nor passing
&null; as end would work.