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, 13 Nov 2009

view this page in

DateTime::setDate

(PHP 5 >= 5.2.0)

DateTime::setDate日付を設定する

説明

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

DateTime オブジェクトの現在の日付をリセットし、別の日付にします。

パラメータ

object

手続き型のみ: date_create() が返す DateTime オブジェクト

year

その日付の年。

month

その日付の月。

day

その日付の日。

返り値

変更した DateTime を返します。

変更履歴

バージョン 説明
5.3.0返り値が NULL から DateTime に変更されました。

例1 オブジェクト指向の使用例

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

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

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

例2 手続き型の使用例

<?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);
?>

上の例の出力は以下となります。

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

参考



add a note add a note User Contributed Notes
DateTime::setDate
melicerte at mailinator dot com
12-Oct-2009 09: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, 13 Nov 2009
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites