DateTimeImmutable::modify タイムスタンプを変更した新しいオブジェクトを作る &reftitle.description; #[\NoDiscard] public DateTimeImmutableDateTimeImmutable::modify stringmodifier タイムスタンプを変更した新しい DateTimeImmutable オブジェクトを作ります。 元のオブジェクトは変更されません。 &reftitle.parameters; modifier &date.formats.parameter; &reftitle.returnvalues; 成功時に DateTimeImmutable を返します。 &return.falseforfailure.style.procedural; &reftitle.errors; 不正な日付/時刻の文字列が渡された場合、 DateMalformedStringException がスローされます。 PHP 8.3.0 より前のバージョンでは、警告が発生していました。 &reftitle.changelog; &Version; &Description; 8.3.0 無効な文字列が渡された場合、 DateTimeImmutable::modifyDateMalformedStringException をスローするようになりました。 これより前のバージョンでは、 警告が発生して false を返していました。 &reftitle.examples; <function>DateTimeImmutable::modify</function> の例 &style.oop; modify('+1 day'); echo $newDate->format('Y-m-d'); ]]> &example.outputs; 月の加減算には注意 modify('+1 month'); echo $newDate1->format('Y-m-d') . "\n"; $newDate2 = $newDate1->modify('+1 month'); echo $newDate2->format('Y-m-d') . "\n"; ]]> &example.outputs; &reftitle.seealso; DateTimeImmutable::add DateTimeImmutable::sub DateTimeImmutable::setDate DateTimeImmutable::setISODate DateTimeImmutable::setTime DateTimeImmutable::setTimestamp