(PHP 5 >= 5.2.0, PHP 7)
DateTime::modify -- date_modify — Alters the timestamp
객체 기반 형식
절차식 형식
Alter the timestamp of a DateTime object by incrementing or decrementing in a format accepted by strtotime().
object
Procedural style only: A DateTime object returned by date_create(). The function modifies this object.
modify
날짜/시간 문자열. 유효한 형식은 날짜와 시간 형식에서 설명하고 있습니다.
메소드 체이닝을 위한 DateTime 객체를 반환합니다.실패 시 FALSE
를 반환합니다.
버전 | 설명 |
---|---|
5.3.6 | Absolute date/time statements now take effect. Previously, only relative parts were used. |
5.3.0 | 반환값을 NULL 에서
DateTime으로 변경. |
Example #1 DateTime::modify() example
객체 기반 형식
<?php
$date = new DateTime('2006-12-12');
$date->modify('+1 day');
echo $date->format('Y-m-d');
?>
절차식 형식
<?php
$date = date_create('2006-12-12');
date_modify($date, '+1 day');
echo date_format($date, 'Y-m-d');
?>
위 예제들의 출력:
2006-12-13
Example #2 Beware when adding or subtracting months
<?php
$date = new DateTime('2000-12-31');
$date->modify('+1 month');
echo $date->format('Y-m-d') . "\n";
$date->modify('+1 month');
echo $date->format('Y-m-d') . "\n";
?>
위 예제의 출력:
2001-01-31 2001-03-03