xFredx xFredx - 9 months ago 66
PHP Question

PHP date increase

I've written a piece of code which converts a date to the specific format and increases it by 1 day.

$mehdate = "2011-11-25";
$mehdate = date ('d m Y', strtotime ('+1 day', strtotime($mehdate)));
echo $mehdate, "\n";

But then I have to increase $mehdate by 1 day one more time.
And I cannot understand how to do that. I already tried

$mehdate = date ('d m Y', strtotime ("+1 day", $mehdate));


$mehdate = date ('d m Y', strtotime ('+1 day', strtotime($mehdate)));

again but it won't work because


returns FALSE.
So, how can I increase the $mehdate which was already formatted?


Your issue can easily be resolved if you use DateTime class.

Try this:

$mehdate = new DateTime('2011-11-25');

$mehdate->modify('+1 day');
echo $mehdate->format('d m Y')."\n";  // Gives 26 11 2011

$mehdate->modify('+1 day');
echo $mehdate->format('d m Y');       // Gives 27 11 2011