downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

DateTime::setISODate> <DateTime::__set_state
Last updated: Fri, 30 Oct 2009

view this page in

DateTime::setDate

(PHP 5 >= 5.2.0)

DateTime::setDateSets the date

Beschreibung

public DateTime DateTime::setDate ( int $year , int $month , int $day )
DateTime date_date_set ( DateTime $object , int $year , int $month , int $day )

Resets the current date of the DateTime object to a different date.

Parameter-Liste

object

Nur bei prozeduralem Aufruf: Ein von date_create() zurückgegebens DateTime Objekt.

year

Year of the date.

month

Month of the date.

day

Day of the date.

Rückgabewerte

Returns the modified DateTime.

Changelog

Version Beschreibung
5.3.0Der Rückgabewert wurde von NULL auf DateTime geändert.

Beispiele

Beispiel #1 Object oriented example usage

<?php
date_default_timezone_set
('Europe/London');

$datetime = new DateTime('2008-08-03 14:52:10');
$datetime->setDate(20081012);

echo 
$datetime->format(DATE_RFC2822);
?>

Beispiel #2 Procedural example usage

<?php
date_default_timezone_set
('Europe/London');

$datetime date_create('2008-08-03 14:52:10');
date_date_set($datetime20081012);

echo 
date_format($datetimeDATE_RFC2822);
?>

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:

Sun, 12 Oct 2008 14:52:10 +0100

Siehe auch



add a note add a note User Contributed Notes
DateTime::setDate
melicerte at mailinator dot com
12-Oct-2009 12:12
Please note that DateTime:setDate() accepts out-of-range values without warnings.
EG:
<?php
date_default_timezone_set
('Europe/London');
$datetime = new DateTime('2008-08-03 14:52:10');
$datetime->setDate(2008, 13, 12);
?>

will reset the DateTime object's date to now. The best approach is to make a wrapper to setDate() which do check for out-of-range values.

DateTime::setISODate> <DateTime::__set_state
Last updated: Fri, 30 Oct 2009
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites