【发布时间】:2018-12-03 10:17:48
【问题描述】:
我想将日期增加一个月,但是, 当前日期有效,但我需要将日期增加一个月(动态)
我从下面的回复中尝试了这个
$regdate=$row2['created_date'];
$onemonth = date($regdate, strtotime("+1 month"));
如何将 $regdate 变量添加到日期函数...?
【问题讨论】:
我想将日期增加一个月,但是, 当前日期有效,但我需要将日期增加一个月(动态)
我从下面的回复中尝试了这个
$regdate=$row2['created_date'];
$onemonth = date($regdate, strtotime("+1 month"));
如何将 $regdate 变量添加到日期函数...?
【问题讨论】:
试试这个
$regdate=$row2['created_date'];
$date = new DateTime($regdate);
$interval = new DateInterval('P1M');
$date->add($interval);
$onemonth = $date->format('Y-m-d');
【讨论】:
在我看来,如果您在 php 语句之前从数据库中编辑数据,我认为这将是完美的:
MYSQL 级别:
SELECT DATE_ADD( yourDate, INTERVAL 1 month ) from your table .
【讨论】:
试试这个
$regdate = strtotime($row2['created_date']);
echo date('Y-m-d',strtotime("+1 month",$regdate));
【讨论】:
尝试以下方法:
在给定日期增加了 1 个月
$date = $row2['created_date'];
$date = date("Y-m-d", strtotime(date("Y-m-d", strtotime($date)) . " +1 month") );
echo $date;
您可以按如下方式添加所需的时间段:
Add day
$date = date("Y-m-d", strtotime(date("Y-m-d", strtotime($date)) . " +1 day") );
Multiple days
$date = date("Y-m-d", strtotime(date("Y-m-d", strtotime($date)) . " +15 days") );
Add week
$date = date("Y-m-d", strtotime(date("Y-m-d", strtotime($date)) . " +1 week") );
Add month
$date = date("Y-m-d", strtotime(date("Y-m-d", strtotime($date)) . " +1 month") );
【讨论】: