Jump to content

List Upcoming 12 months since Current Month


hitk

Recommended Posts

My Issue is similar to http://www.phpfreaks.com/forums/index.php?topic=139559

 

I want to list Upcoming 12 Months from today's month.

 

Ex. We are in July Month so list should be,

 

July 2010

August 2010

September 2010

...

.

.

.

June 2011

 

I am using smarty, so plz, let me know.

^^^ the posted code will experience problems on the last day(s) of the month because it uses the current date/time and it will skip and produce duplicates when the current day number does not exist in the months you are looping over. Using mktime() would be better because you can easily specify the first day of the month (or any day that exists in every month) and in fact since strtotime() uses mktime internally, mktime would be slightly faster.

<?php
$month = date('n'); // current month
for ($x = 0; $x < 12; $x++) {
echo date('F Y', mktime(0,0,0,$month + $x,1)) . '<br />';
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.