PHP 日付の加算、減算 date('Ymd', strtotime('1 month'))

2017/06/18(0) 83

PHP 日付の加算、減算 date(

目次

date('Ymd', strtotime('1 month'))
DateTimeクラスで加算、減算


date('Ymd', strtotime('1 month'))

例)
date("Ymd", strtotime("1 day"))
date("Ymd", strtotime("1 month"))
date("Ymd", strtotime("1 year"))
date("Ymd", strtotime("-1 week"))


DateTimeクラスで加算、減算

$date = new DateTime('2018-06-18 08:26:12');
$date->modify('+3 hours');
$date->modify('+1 weeks');
$date->modify('+1 months');
$date->modify('+1 days');
echo $date->format('Ymd H');