morgi morgi - 1 year ago 99
PHP Question

Current date + 2 months

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

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


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

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

Answer Source

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

echo date('d/m/Y', strtotime('+2 months'));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download