phforum wrote:
If user input the date is 2006-07-01. How to convert it to last year
2005-07-01?
If this is the fixed pattern, the simplest thing you can do is something as
follows:
$date = "2006-07-01";
list($y, $m, $d) = explode('-', $date);
$newdate = (--$y) . "-$m-$d";
However, this will cause problems when the date is the 29th of February in a
leap year, while the previous is a regular year. To fix this, you can apply
the strtotime() function:
$date = "2004-02-29";
$ts = strtotime("last year", strtotime($date));
$newdate = date('Y-m-d', $ts);
HTH;
JW