Simon Fabb Simon Fabb - 1 year ago 88
PHP Question

PHP date from today to 4 months

Does anyone know why this keeps on showing the date 01-05-70?

$effectiveDate = strtotime("+4 months", strtotime($effectiveDate)); // returns timestamp
echo date('d-m-y',$effectiveDate); // formatted version

I want it to print today's date + 4 months.

Answer Source

In your code $effectiveDate contains an invalid date. So strtotime() returns the unix epoch Jan 1, 1970.

But you shouldn't need that variable at all if all you want is the date four months from now.

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