如何在 PHP 中修改日期/时间变量


How to modify a date/time variable in PHP

我正在接收变量$CheckIn $CheckIn是 Y-m-d 格式的日期,如何创建值为 +8 天的 $Checkout 变量签入后。

$checkout = date('Y-m-d', strtotime($checkin. ' + 8 days'));

试试这个:

$Date = "2010-09-17";
echo date('Y-m-d', strtotime($Date. ' + 8 days'));//save this in any variable

DateTime()

$date = new DateTime($checkin);
$date->modify('+8 days');
echo $date->format('Y-m-d');