1

I want how to add days, I try this

$start = '06/07/2017'
echo $start;
echo "<br>";
echo date('d/m/Y', strtotime(' + 1 days', strtotime($start)));

But return this

06/07/2017
08/06/2017

What is the problem?

NARTONIC
  • 452
  • 10
  • 22

2 Answers2

9

Try this,

<?php
$start = '06/07/2017';
echo $start;
$start = str_replace("/","-",$start);
echo "<br>";
echo date("d/m/y", strtotime(date('d-m-Y', strtotime(' + 1 days', strtotime($start)))));

Note: Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed. If, however, the year is given in a two digit format and the separator is a dash (-, the date string is parsed as y-m-d.

Source link.

Rahul
  • 18,271
  • 7
  • 41
  • 60
1
<?php
//old code
$str = '06/07/2017';
$date = DateTime::createFromFormat('d/m/Y', $str);
$start_old =  $date->format('d-m-Y'); 
echo   date('d/m/Y', strtotime($start_old . ' +1 day'));
echo "<br>";
//new updated code
$start = '06/07/2017';
echo DateTime::createFromFormat('d/m/Y', $start)
    ->add(new DateInterval('P1D'))
    ->format('d/m/Y');
?>

Using DateTime.

fiddle

Rushil K. Pachchigar
  • 1,263
  • 2
  • 21
  • 40