如何在php中从数据库中获取日期的基础上增加一个月的日期

piwo6bdm  于 2021-06-18  发布在  Mysql
关注(0)|答案(4)|浏览(311)

这个问题在这里已经有答案了

增加一个月的日期(18个答案)
两年前关门了。
我想增加一个月的日期,但,目前的日期是工作,但我的需要是增加一个月的日期(动态)
我从下面的回应中试过这个

$regdate=$row2['created_date'];
 $onemonth = date($regdate,  strtotime("+1 month"));

如何将$regdate变量添加到日期函数。。。?

zysjyyx4

zysjyyx41#

在我看来,如果您在php语句之前从数据库中编辑数据,我认为这将是完美的:
mysql级别:

SELECT DATE_ADD( yourDate, INTERVAL 1 month ) from your table .
shyt4zoc

shyt4zoc2#

试试这个

$regdate = strtotime($row2['created_date']);
echo date('Y-m-d',strtotime("+1 month",$regdate));
1mrurvl1

1mrurvl13#

请尝试以下操作:
在给定日期内添加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") );
3zwtqj6y

3zwtqj6y4#

试试这个

$regdate=$row2['created_date'];
$date = new DateTime($regdate);
$interval = new DateInterval('P1M');

$date->add($interval);
$onemonth = $date->format('Y-m-d');

相关问题