Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
<?php // Create from "now" $now = new DateTimeImmutable(); echo $now->format('Y-m-d H:i:s'); // Create from a string $birthday = new DateTimeImmutable('1990-06-15'); echo $birthday->format('l, F j, Y'); // Friday, June 15, 1990 // modify() returns NEW object (immutable) $nextWeek = $now->modify('+7 days'); $lastMonth = $now->modify('-1 month'); $nextYear = $now->modify('+1 year'); echo $nextWeek->format('Y-m-d'); echo $lastMonth->format('Y-m-d'); // Create from a specific format $d = DateTimeImmutable::createFromFormat('d/m/Y', '25/12/2024'); echo $d->format('Y-m-d'); // 2024-12-25 // Timestamps $ts = $now->getTimestamp(); $fromTs = (new DateTimeImmutable())->setTimestamp($ts);
Result
Open