0
    $date = "2016-10-04";
    $date1 = str_replace('-', '/', $date);
    $tomorrow = date('y-m-d',strtotime($date1 . "+1 days"));

    echo $tomorrow;

Using above php code add one day to the given value. Finally it returns 16-10-05. But I need it with full year as 2016-10-05. How I get that?

isuru
  • 3,385
  • 4
  • 27
  • 62

5 Answers5

3

try this, use 'Y' not 'y'

$date = "2016-10-04";
$date1 = str_replace('-', '/', $date);
$tomorrow = date('Y-m-d',strtotime($date1 . "+1 days"));

echo $tomorrow;

DEMO

Dave
  • 3,073
  • 7
  • 20
  • 33
3

For full year use 'Y' instead of 'y'

$date = "2016-10-04";
$date1 = str_replace('-', '/', $date);
$tomorrow = date('Y-m-d',strtotime($date1 . "+1 days"));

echo $tomorrow;
Al Foиce ѫ
  • 4,195
  • 12
  • 39
  • 49
Rajesh Patel
  • 1,946
  • 16
  • 20
2

Just use 'Y-m-d' instead of 'y-m-d'

See http://php.net/manual/en/function.date.php for the full list of date format values.

compsmart
  • 161
  • 1
  • 3
2

You need to change 'y-m-d' to 'Y-m-d' in your date function.

Y - A four digit representation of a year
y - A two digit representation of a year

Ref link: http://www.w3schools.com/php/func_date_date_format.asp

Try below code:

$date = "2016-10-04";
$date1 = str_replace('-', '/', $date);
$tomorrow = date('Y-m-d',strtotime($date1 . "+1 days"));

echo $tomorrow;
Arti
  • 2,993
  • 11
  • 68
  • 121
2

It is always better to use the DateTime. The below should work!

$date = new DateTime("2016-10-04");
$interval = new DateInterval('P1D');
echo $date->add($interval)->format("Y-m-d");

Note: You can get rid of $date1 = str_replace('-', '/', $date); which seems unnecessary to me.

You can read more on DateTime and DateInterval from the PHP manual.

Cheers!

masterFly
  • 1,072
  • 12
  • 24