Forum Moderators: coopster
$date = date ( 'F' );
// - 1 month from today
echo date("F", mktime (0,0,0,-2,0,0,0));
echo date ( 'F', strtotime ( '-1 month' . $date ) );
The strtotime works but apparently is incorrect as it's only 30 days. Also, I nned to have -2 month all the way through to plus2 months as well...
To avoid this, you should substract three days from the current date if the day of the month is greater than 28 (to avoid even confusion during Feb/March change as in this example).
// Grab the current month and year
list($month, $year) = explode('-', date('m-Y'));
// Set the date to the first day of this month
$first = mktime(0, 0, 0, $month, 1, $year);
// We want to grab 2 months past, 2 months future
foreach (range(-2, 2) as $n) {
$n = ($n >= 0) ? "+$n" : $n;
print strftime('%B', strtotime("$n month", $first)) . "\n";
}