morgi morgi - 4 months ago 15
PHP Question

Current date + 2 months

I wrote this piece of code in order to display the current date + 2 months :

<?php
$date = date("d/m/Y");
$date = strtotime(date("d/m/Y", strtotime($date)) . "+2 months");
$date = date("d/m/Y",$date);
echo $date;
?>


It does not seem to work as it displays : 01/03/1970.

What am I doing wrong?

Thanks for your help.

EDIT :

After reading comments and answers, I simplified and corrected it.

<?php
$date = date("d/m/Y", strtotime(" +2 months"));
echo $date;
?>

Answer

You're missing the second argument for the second strtotime() call:

echo date('d/m/Y', strtotime('+2 months'));
Comments