Return current and previous months in Zend Framework, considering passing into a new year as well.
Zend Framework, through Zend_Date() offers a quick solution for this problem.
With the get() function we can return any part of the current date, and with the sub() function we can substract 1 month to get the previous month date.
$date = new Zend_Date();
$thisMonth = $date->get(Zend_Date::MONTH);
$thisYear = $date->get(Zend_Date::YEAR);
$lastMonth = $date->get(Zend_Date::MONTH);
$lastYear = $date->get(Zend_Date::YEAR);