Forum Moderators: coopster
I would use strtotime [ca.php.net] but it takes a timestamp so...
// split into individual y,m,d
$datearr = split("-",$mydate);
// make timestamp
$timestamp = mktime(0,0,0,$datearr[1],$datearr[2],$datearr[0]);
// increment date, you can alter the number of days obviously
$newtimestamp = strtotime("-5 days",$timestamp);
// change to readable date
$mynewdate = strftime("%Y-%m-%d",$newtimestamp);
that should work
// get todays date
$mydate = date("Y m d");
// split into individual y,m,d
$datearr = split("-",$mydate);
// make timestamp
$timestamp = mktime(0,0,0,$datearr[1],$datearr[2],$datearr[0]);
// increment date, you can alter the number of days obviously
$newtimestamp = strtotime("-2 days",$timestamp);
// change to readable date
$mynewdate = strftime("%Y-%m-%d",$newtimestamp);
echo $mydate; // outputs 2003 09 30
echo $mynewdate; // outputs 2002-11-28
This code subtracts 2 days which is fine, but then it also subtracts a year and adds two months........
Can you see what I am doing wrong?