ajsie ajsie - 1 month ago 6
PHP Question

Date minus 1 year?

I've got a date in this format:

2009-01-01


How do I return the same date but 1 year earlier?

CMS CMS
Answer

You can use strtotime:

$date = strtotime('2010-01-01 -1 year');

The strtotime function returns a unix timestamp, to get a formatted string you can use date:

echo date('Y-m-d', $date); // echoes '2009-01-01'