Note: If you are trying to get 02.29 for non leap year it will return 03.01
Example:
<?php
new DateTimeImmutable('2017-02-29') // 2017-03-01
?>
(PHP 5 >= 5.5.0, PHP 7)
This class behaves the same as DateTime except it never modifies itself but returns a new object instead.
$format
, string $time
[, DateTimeZone $timezone
] ) : DateTimeImmutable$hour
, int $minute
[, int $second
= 0
[, int $microseconds
= 0
]] ) : DateTimeImmutable
Note: If you are trying to get 02.29 for non leap year it will return 03.01
Example:
<?php
new DateTimeImmutable('2017-02-29') // 2017-03-01
?>
class MyDateTime extends DateTimeImmutable
{
public function addDay(int $amount): MyDateTime
{
return $this->add(new DateInterval("P" . $amount . "D"));
}
}
addDay will return DateTimeImmutable not MyDateTime. It looks like there is no "return static;"
i wish i would be
Here's a simple example on how this class works :
// Create a DateTimeImmutable Object
$date = new DateTimeImmutable('2000-01-01');
// "Change" that object and assign it's value to a new variable
$date2 = $date->add(new DateInterval('P6M5DT24H'));
// Check out the content of the two variables
echo $date->format('Y-m-d') . "\n";
// 2000-01-01
echo $date2->format('Y-m-d') . "\n";
// 2000-07-07