DateTime
PHP Manual

DateTime::setDate

(PHP 5 >= 5.2.0)

DateTime::setDateSets the date

설명

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.

인수

object

절차식 전용: date_create()가 반환하는 DateTime 객체.

year

Year of the date.

month

Month of the date.

day

Day of the date.

반환값

Returns the modified DateTime.

변경점

버전 설명
5.3.0반환값을 NULL에서 DateTime으로 변경.

예제

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

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

위 예제의 출력:

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

참고


DateTime
PHP Manual