(PHP 5 >= 5.5.0, PHP 7, PHP 8)
DateTimeImmutable::setDate — Sets the date
Returns a new DateTimeImmutable object with the current date of the DateTimeImmutable object set to the given date.
nesneSadece yordamsal tarz: date_create() tarafından bir DateTime nesnesi döndürülür. İşlev bu nesnede değişiklik yapar.
yearYear of the date.
monthMonth of the date.
dayDay of the date.
Verisi değişmiş DateTimeImmutable nesnesi döner.
Örnek 1 DateTimeImmutable::setDate() example
Nesne yönelimli kullanım
<?php
$date = new DateTimeImmutable();
$newDate = $date->setDate(2001, 2, 3);
echo $newDate->format('Y-m-d');
?>Yukarıdaki örneklerin çıktısı:
2001-02-03
Örnek 2 Values exceeding ranges are added to their parent values
<?php
$date = new DateTimeImmutable();
$newDate = $date->setDate(2001, 2, 28);
echo $newDate->format('Y-m-d') . "\n";
$newDate = $date->setDate(2001, 2, 29);
echo $newDate->format('Y-m-d') . "\n";
$newDate = $date->setDate(2001, 14, 3);
echo $newDate->format('Y-m-d') . "\n";
?>Yukarıdaki örneğin çıktısı:
2001-02-28 2001-03-01 2002-02-03