(PHP 5 >= 5.2.0)
DateTime::setDate — Sets the date
Styl obiektowy
Styl proceduralny
Resets the current date of the DateTime object to a different date.
Procedural style only: A DateTime object returned by date_create(). The function modifies this object.
Year of the date.
Month of the date.
Day of the date.
Returns the modified DateTime object lub FALSE w przypadku błędu.
Wersja | Opis |
---|---|
5.3.0 | Zmieniono zwracaną wartość z NULL na DateTime. |
Przykład #1 DateTime::setDate() example
Styl obiektowy
<?php
$date = new DateTime();
$date->setDate(2001, 2, 3);
echo $date->format('Y-m-d');
?>
Styl proceduralny
<?php
$date = date_create();
date_date_set($date, 2001, 2, 3);
echo date_format($date, 'Y-m-d');
?>
Powyższe przykłady wyświetlą:
2001-02-03
Przykład #2 Values exceeding ranges are added to their parent values
<?php
$date = new DateTime();
$date->setDate(2001, 2, 28);
echo $date->format('Y-m-d') . "\n";
$date->setDate(2001, 2, 29);
echo $date->format('Y-m-d') . "\n";
$date->setDate(2001, 14, 3);
echo $date->format('Y-m-d') . "\n";
?>
Powyższy przykład wyświetli:
2001-02-28 2001-03-01 2002-02-03