ubuntu ubuntu - 1 year ago 104
PHP Question

add some days to current date in php

I have this code

$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

Answer Source

You can use strtotime() function to add days to current date. Please see the below :

   $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;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download