Have a look at the DateTime
class. It should do the calculations correctly and the date formats are compatible with strttotime
. Something like:
$datestring='2011-03-30 first day of last month';
$dt=date_create($datestring);
echo $dt->format('Y-m'); //2011-02