Subscribe For Free Updates!

We'll not spam mate! We promise.

Jul 7, 2013

PHP Get Last 12 Months


PHP to get last 12 months : 

 The following coding is used to get previous 12 months by using PHP.



<?php

for ($t = 1; $t <= 12; $t++) {
    echo date("F Y m", strtotime( date( 'Y-m-01' )." -$t months"));
    echo "<br />";
}

?>

 Output of this code is :

June 2013 06
May 2013 05
April 2013 04
March 2013 03
February 2013 02
January 2013 01
December 2012 12
November 2012 11
October 2012 10
September 2012 09
August 2012 08
July 2012 07



 Here date "F Y m" is used to make the date format in above format. you can store these dates in arrat also by using below code.


<?php
for ($t = 1; $t <= 12; $t++) {
    $mnt[]= date("F Y m", strtotime( date( 'Y-m-01' )." -$t months"));
}
?>


Here $mnt is php array variable with last 12 months.

TechniqZone Socializer Widget
SOCIALIZE IT →
FOLLOW US →
SHARE IT →

0 comments:

Post a Comment