Date minus 1 year?


Question

I've got a date in this format:

2009-01-01

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

1
84
11/29/2011 6:30:12 PM

Accepted 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'
121
10/27/2014 5:19:36 PM

Use strtotime() function:

  $time = strtotime("-1 year", time());
  $date = date("Y-m-d", $time);

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon