Mohammed H. S.
Mohammed H. S.

Reputation: 499

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

Upvotes: 1

Views: 10268

Answers (4)

Karol Gasienica
Karol Gasienica

Reputation: 2904

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";
?>

Upvotes: 4

Azeez Kallayi
Azeez Kallayi

Reputation: 2642

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;
 ?>

Upvotes: 0

Md Hasibur Rahaman
Md Hasibur Rahaman

Reputation: 1061

it may help you

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

Upvotes: 0

Blinkydamo
Blinkydamo

Reputation: 1584

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

Upvotes: 6

Related Questions