CodeIgniter Forums
generate 12 mini-calendars - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: generate 12 mini-calendars (/thread-24838.html)



generate 12 mini-calendars - El Forum - 11-21-2009

[eluser]timj[/eluser]
Why doesn't this work? It clearly generates [what appears to be correct when echoed] 12 incremented $this->calendar->generate(Year, month) statements, but every calendar is the default (current) month in the correct year. In other words, it is correctly reading the year and correctly incrementing the month... it is just not reading the month.

More to the point, I guess, is there an easier way to do this?

Code:
function get_months($date1, $date2)
{

$date1 = date('Y-m',strtotime($date1));
$date2 = date('Y-m',strtotime($date2));

if($date1 < $date2)
{
   $past = $date1;
   $future = $date2;
}
else
{
   $past = $date2;
   $future = $date1;
}

$months = array();
for($i = $past; $past<=$future; $i++)
{
   $timestamp = strtotime($past.'-1');
   $months[] = date('Y, m',$timestamp);
   $past = date('Y-m',strtotime('+1 month',$timestamp));  
}

return $months;
}

$this_year = date('Y-m', strtotime('now'));
$next_year = date('Y-m', strtotime('now +12 months'));

$data = get_months($this_year, $next_year);

for($i=0;$i<count($data);$i++)
{
     echo $this->calendar->generate($data[$i]);
     echo 'generate('.$data[$i].')<br />';
}



generate 12 mini-calendars - El Forum - 12-05-2009

[eluser]timj[/eluser]
I was hoping someone might attempt to answer this question. Is it a limitation of the Calendar Helper?