addYears.php
Table of Contents
Functions
- addYears() : DateTimeImmutable
- Returns a copy of a date shifted by a number of years, clamping day overflow.
Functions
addYears()
Returns a copy of a date shifted by a number of years, clamping day overflow.
addYears(DateTimeInterface $date, int $years) : DateTimeImmutable
A new DateTimeImmutable is returned ; the source date is never modified. Delegates
to addMonths( $date , $years * 12 ), so a leap day clamps the same way : 2028-02-29
- 1 year lands on
2029-02-28, 2029 not being a leap year, rather than overflowing to2029-03-01.
Parameters
- $date : DateTimeInterface
-
The source date.
- $years : int
-
The number of years to add (negative to subtract).
Tags
Return values
DateTimeImmutable —A new immutable date shifted by $years years, day-clamped.