DateTimeImmutable::add

(PHP 5 >= 5.5.0)

DateTimeImmutable::add Adds an amount of days, months, years, hours, minutes and seconds

Description

public DateTimeImmutable DateTimeImmutable::add ( DateInterval $interval )

Like DateTime::add() but works with DateTimeImmutable.

Коментарии

Автор:
Please note, add() works a litte different than for DateTime-Objects.

Since DateTimeImmutable is in fact immutable. A line like this will not work:

    $di = new DateTimeImmutable("2018-12-12T10:00:00");
    $di->add(new DateInterval('PT45M')); // $di unchanged !!!

compared to

    $dt = new DateTime("2018-12-12T10:00:00");
    $dt->add(new DateInterval('PT45M')); // added 45 minutes

so you need to write

    $di = new DateTimeImmutable("2018-12-12T10:00:00");
    $di = $di->add(new DateInterval('PT45M')); // $di now changed
2018-12-13 01:00:53
http://php5.kiev.ua/manual/ru/datetimeimmutable.add.html

    Поддержать сайт на родительском проекте КГБ