(PHP 5 >= 5.2.0)
DateTime::setDate — Sets the date
Stil obiect-orientat
Stil procedural
Resets the current date of the DateTime object to a different date.
Doar stilul procedural: Un obiect DateTime întors de date_create(). Funcția modifică acest obiect.
Year of the date.
Month of the date.
Day of the date.
Întoarce obiectul DateTime pentru înlănțuirea metodelor sau FALSE în cazul eșecului.
Versiunea | 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