ubuntu ubuntu - 1 month ago 8
PHP Question

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

Answer

You can use strtotime() function to add days to current date. 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;
 ?>
Comments