tags:

views:

19

answers:

2

I'm using the David Walsh PHP calendar script and need to format my date arguments like this:

draw_calendar(7,2009);

I want to get today's Month and Year as well as the next month and the month after that (so current month, plus one, plus one). How can I call the function three times in succession to generate these three calendars only knowing today's Month and Year?

-Brandon

A: 
function increment(&$month, &$year) {
    if (++$month > 12) {
        $month -= 12;
        $year++;
    }
}
$month = 11;
$year = 2009;
echo "Month: $month, Year: $year\n";
# Outputs Month: 11, Year: 2009
increment($month, $year);
echo "Month: $month, Year: $year\n";
# Outputs Month: 12, Year: 2009
increment($month, $year);
echo "Month: $month, Year: $year\n";
# Outputs Month: 1, Year: 2010
soulmerge
+1  A: 

I am sure there are more elegant ways however how's this:

$onemonth = strtotime('+1 month');
$twomonth = strtotime('+2 month');

draw_calendar(date('n'), date('Y'));
draw_calendar(date('n', $onemonth), date('Y', $onemonth));
draw_calendar(date('n', $twomonth), date('Y', $twomonth));
plod
Thanks, I think this will work. I didn't think I could use strings but that strtotime() function is helpful.
Brandon