Click to See Complete Forum and Search --> : Generate months and year


bjen
05-22-2007, 03:52 AM
Hi,

I facing some problem, hope someone can give me some advice. Below is my coding to generate the month and year.

switch ($month)
{
case 1: $months = array(1,2,3,4,5,6); break;
case 2: $months = array(2,3,4,5,6,7); break;
case 3: $months = array(3,4,5,6,7,8 ); break;
case 4: $months = array(4,5,6,7,8,9); break;
case 5: $months = array(5,6,7,8,9,10); break;
case 6: $months = array(6,7,8,9,10,11); break;
case 7: $months = array(7,8,9,10,11,12); break;
case 8: $months = array(8,9,10,11,12,1); break;
case 9: $months = array(9,10,11,12,1,2); break;
case 10: $months = array(10,11,12,1,2,3); break;
case 11: $months = array(11,12,1,2,3,4); break;
case 12: $months = array(12,1,2,3,4,5); break;
}


foreach ($months as $m) {
echo date("M - Y", mktime(0,0,0,$m,1,$currentYear));
}

The year is not change once case 9, case 10, case 11 and case 12 is executed.

Output Script:
Oct - 2007
Nov – 2007
Dec – 2007
Jan – 2007
Feb – 2007
Mar – 2007

The output supposes like below:

Oct - 2007
Nov – 2007
Dec – 2007
Jan – 2008
Feb – 2008
Mar – 2008

please help!

Your help will be very much appreciated.

Thank you

Charles
05-22-2007, 05:48 AM
I'm not exactly sure what it is that you are up to but I suspect that you want to be using strtotime instead of mktime. See http://www.php.net/manual/en/function.strtotime.php .

bokeh
05-22-2007, 07:03 AM
Why are you making things so complicated? The following is relative to the current month:<?php

for($i = 0; $i < 6; $i++)
{
echo date("M - Y", mktime(0,0,0,date('n')+$i,1))."<br>\n";
}

?>