Create an immutable DateTime from a mutable one before PHP 5.6

suggest change

To create a \DateTimeImmutable in PHP 5.6 and later, use:

\DateTimeImmutable::createFromMutable($mutable);

Before PHP 5.6 you can use:

\DateTimeImmutable::createFromFormat(\DateTime::ISO8601, $mutable->format(\DateTime::ISO8601), $mutable->getTimezone());

DateTime::ISO8601 drops microseconds and is not a complete ISO-8601 format.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents