简体   繁体   English

在PHP中添加一些日期到当前日期

[英]add some days to current date in php

I have this code 我有这个代码

<?php
$date =date(Y-m-d);
$day = 5;
$newdate= $date+$day
echo "today is:"$date;
echo "<br> and after 5 days is :"$newdate;
?>

I want the result is today is :2016-11-2 and after 5 days is : 2016-11-7 我希望结果是今天是:2016-11-2而5天后是:2016-11-7

It should help you: 它应该可以帮助您:

echo date('Y-m-d', strtotime($date. ' + 5 days'));

So it will be like follows: 因此将如下所示:

<?php
$date = date('Y-m-d');
$newdate = date('Y-m-d', strtotime($date.' + 5 days'));
echo "today is: $date";
echo "<br> and after 5 days is: $newdate";
?>

Try this 尝试这个

$date    = new DateTime();               // Creates new DatimeTime for today
$newdate = $date->modify( '+ 5 days' );  // Adds 5 days
echo $newdate->format( 'Y-m-d' );        // Echo and format the newdate to the wanted format

it may help you 它可以帮助你

$date = "Mar 03, 2016";
$date = strtotime($date);
$date = strtotime("+7 day", $date);
echo date('M d, Y', $date);

You can use strtotime() function to add days to current date. 您可以使用strtotime()函数将天添加到当前日期。 Please see the below : 请参阅以下内容:

 <?php
   $date =date("Y-m-d");
   $day = 5;
   $newdate=date('Y-m-d', strtotime("+$day days"));
   echo "today is:".$date;
   echo "<br> and after 5 days is :".$newdate;
 ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM