如何在 PHP 中向 $Date 添加天数?
要在 PHP 中向 $Date 添加天数,代码如下−
示例
<?php $date = "2019-11-11"; echo "Displaying date...
"; echo "Date = $date"; echo "
Displaying updated date...
"; echo date('Y-m-d', strtotime($date. ' + 20 days')); ?>
输出
这将产生以下输出−
Displaying date... Date = 2019-11-11 Displaying updated date... 2019-12-01
示例
现在让我们看另一个示例 −
<?php $date = date_create("2019-11-11"); echo "Displaying Date..."; echo date_format($date,"Y/m/d"); date_add($date, date_interval_create_from_date_string("25 days")); echo "
Displaying Updated Date..."; echo "
".date_format($date, "Y/m/d"); ?>
输出
这将产生以下输出−
Displaying Date...2019/11/11 Displaying Updated Date... 2019/12/06
广告