How to list previous 12 months since current month in PHP

Hi friends,

Here is the how to list previous 12 months since current month in PHP in a very easy and self explanatory way, please use this code and let me know if you face any issue.

To get previous 12 months since current month you can use below code:

$month = date('n'); // current month
for ($m = 0; $m < 12; $m++) {
 echo date('F - Y', mktime(0,0,0,$month - $m,1)) . '
';
}

Result:
May - 2013
April - 2013
March - 2013
February - 2013
January - 2013
December - 2012
November - 2012
October - 2012
September - 2012
August - 2012
July - 2012
June - 2012

Guys please let me know if you face any issue with this code or if you want more help. Use comment box and share your thought. If this help you please share this post with your friends, enjoy!!!

Tagged , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *