(PHP 5 >= 5.2.0, PHP 7)
DateTime::setDate -- date_date_set — Sets the date
Stil obiect-orientat
Stil procedural
Resets the current date of the DateTime object to a different date.
objectDoar stilul procedural: Un obiect DateTime întors de date_create(). Funcția modifică acest obiect.
yearYear of the date.
monthMonth of the date.
dayDay of the date.
Întoarce obiectul
DateTime pentru
înlănțuirea metodelor sau FALSE în cazul eșecului.
| Versiune | Descriere |
|---|---|
| 5.3.0 | A fost schimbată valoarea întoarsă în caz de succes
din NULL în DateTime. |
Example #1 DateTime::setDate() example
Stil obiect-orientat
<?php
$date = new DateTime();
$date->setDate(2001, 2, 3);
echo $date->format('Y-m-d');
?>
Stil procedural
<?php
$date = date_create();
date_date_set($date, 2001, 2, 3);
echo date_format($date, 'Y-m-d');
?>
Exemplele de mai sus vor afișa:
2001-02-03
Example #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";
?>
Exemplul de mai sus va afișa:
2001-02-28 2001-03-01 2002-02-03