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