tags:

views:

114

answers:

3
+1  Q: 

date minus 1 year?

ive got a date in this format:

2009-01-01

how do i return same date but 1 year earlier?

+5  A: 

Use strtotime() function:

  $time = strtotime("-1 year", time());
  $date = date("Y-m-d");
Alex
+9  A: 

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'
CMS
+2  A: 
// set your date here
$mydate = "2009-01-01";

/* strtotime accepts two parameters.
The first parameter tells what it should compute.
The second parameter defines what source date it should use. */
$lastyear = strtotime("-1 year", strtotime($mydate));

// format and display the computed date
echo date("Y-m-d", $lastyear);
Nirmal