Past 12 months

Hi guys

I can get the next 12 months but I cant get the previous 12 months ??


$month_from_date = date("Y-m-01"); // any date.

for ($a=0; $a<=12; $a++)
{

Hi wazo, PHP 5.3 has a bunch of awesome date-related improvements. Is that version available to you?

I tried that but its not taking affect

That loop gives you the next 12 months?
Then try this to get the previous 12:


$the_month_array= date("Y-m", strtotime("$month_from_date - 1 month"));

sorry


$month_from_date = date("Y-m-01"); // any date.

for ($a=0; $a<=12; $a++)
{



$the_month_array= date("Y-m", strtotime("$month_from_date + 1 month"));

}

A part of your code is missing?

Adapt to your own needs. (i used echo here but you can put it in your array)

change the -/+ in “-$a month” to go forward or backwards in time(months)

<?
$month_from_date = date("Y-m-01"); // any date.

for ($a=0; $a<=12; $a++)
{
$date = strtotime("-$a month", strtotime($month_from_date));
echo date("Y-m-d", $date)."<br>";
}
?>