DateTime
PHP Manual

DateTime::setDate

(PHP 5 >= 5.2.0)

DateTime::setDateSets the date

Beschreibung

Objektorientierter Stil

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

Prozeduraler Stil

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ückgegebenes DateTime-Objekt. Diese Funktion verändert dieses Objekt.

year

Year of the date.

month

Month of the date.

day

Day of the date.

Rückgabewerte

Returns the modified DateTime objectIm Fehlerfall wird FALSE zurückgegeben..

Changelog

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

Beispiele

Beispiel #1 DateTime::setDate() example

Objektorientierter Stil

<?php
$date 
= new DateTime();
$date->setDate(200123);
echo 
$date->format('Y-m-d');
?>

Prozeduraler Stil

<?php
$date 
date_create();
date_date_set($date200123);
echo 
date_format($date'Y-m-d');
?>

The above examples will output:

2001-02-03

Beispiel #2 Values exceeding ranges are added to their parent values

<?php
$date 
= new DateTime();

$date->setDate(2001228);
echo 
$date->format('Y-m-d') . "\n";

$date->setDate(2001229);
echo 
$date->format('Y-m-d') . "\n";

$date->setDate(2001143);
echo 
$date->format('Y-m-d') . "\n";
?>

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:

2001-02-28
2001-03-01
2002-02-03

Siehe auch


DateTime
PHP Manual