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
[edit] Last updated: Fri, 23 Mar 2012

view this page in

DateTime::setDate

date_date_set

(PHP 5 >= 5.2.0)

DateTime::setDate -- date_date_setSets the date

Açıklama

Nesne yönelimli kullanım

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

Yordamsal kullanım

DateTime date_date_set ( DateTime $object , int $year , int $month , int $day )

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

Değiştirgeler

nesne

Sadece yordamsal tarz: date_create() tarafından bir DateTime nesnesi döndürülür. İşlev bu nesnede değişiklik yapar.

year

Year of the date.

month

Month of the date.

day

Day of the date.

Dönen Değerler

Değişmiş DateTime nesnesinden başarısızlık durumunda FALSE döner.

Sürüm Bilgisi

Sürüm: Açıklama
5.3.0Başarı durumunda dönen değer artık NULL değil, DateTime oldu.

Örnekler

Örnek 1 DateTime::setDate() example

Nesne yönelimli kullanım

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

Yordamsal kullanım

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

Yukarıdaki örneklerin çıktısı:

2001-02-03

Örnek 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";
?>

Yukarıdaki örneğin çıktısı:

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

Ayrıca Bakınız



add a note add a note User Contributed Notes DateTime::setDate
wkeevers96 at yahoo dot com 19-Mar-2012 05:44
Date validity can be checked with a custom class.
remy215 at laposte dot net 11-Jan-2012 10:59
Be warned, DateTime::setDate() does not check for invalid input.

Illustration:
<?php
$dt
= new DateTime();
$dt->setDate(2012, 11, 31); // returns DateTime object and not false although this date does not exist
echo $dt->format('Y-m-d'); // output: 2012-12-01
?>

No error was generated on entering a non existing date, php silently changed it.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites