Function to find out last 12 months details from the current date
function getLast12MonthsDetails(){
$month = date('m');
$year = date('Y');
$i = 1;
$date = a rray();
while($i<=12){
$timestamp = mktime(0,0,0,$month,1,$year);
$date[$i]['month'] = date('F', $timestamp);
$date[$i]['monthCount'] = date('m', $timestampts);
$date[$i]['monthShort'] = date('M', $timestamp);
$date[$i]['daysInMonth'] = date('t', $timestamp);
$date[$i]['year'] = date('Y', $timestamp);
$date[$i]['yearShort'] = date('y', $timestamp);
$month--;
$i++;
}
return $date;
}
calling the function
print_r(getLast12MonthsDetails());
will return the following details in an array
Array
(
[1] => Array
(
[month] => July
[monthCount] => 12
[monthShort] => Jul
[daysInMonth] => 31
[year] => 2009
[yearShort] => 09
)
[2] => Array
(
[month] => June
[monthCount] => 12
[monthShort] => Jun
[daysInMonth] => 30
[year] => 2009
[yearShort] => 09
)
[3] => Array
(
[month] => May
[monthCount] => 12
[monthShort] => May
[daysInMonth] => 31
[year] => 2009
[yearShort] => 09
)
[4] => Array
(
[month] => April
[monthCount] => 12
[monthShort] => Apr
[daysInMonth] => 30
[year] => 2009
[yearShort] => 09
)
[5] => Array
(
[month] => March
[monthCount] => 12
[monthShort] => Mar
[daysInMonth] => 31
[year] => 2009
[yearShort] => 09
)
[6] => Array
(
[month] => February
[monthCount] => 12
[monthShort] => Feb
[daysInMonth] => 28
[year] => 2009
[yearShort] => 09
)
[7] => Array
(
[month] => January
[monthCount] => 12
[monthShort] => Jan
[daysInMonth] => 31
[year] => 2009
[yearShort] => 09
)
[8] => Array
(
[month] => December
[monthCount] => 12
[monthShort] => Dec
[daysInMonth] => 31
[year] => 2008
[yearShort] => 08
)
[9] => Array
(
[month] => November
[monthCount] => 12
[monthShort] => Nov
[daysInMonth] => 30
[year] => 2008
[yearShort] => 08
)
[10] => Array
(
[month] => October
[monthCount] => 12
[monthShort] => Oct
[daysInMonth] => 31
[year] => 2008
[yearShort] => 08
)
[11] => Array
(
[month] => September
[monthCount] => 12
[monthShort] => Sep
[daysInMonth] => 30
[year] => 2008
[yearShort] => 08
)
[12] => Array
(
[month] => August
[monthCount] => 12
[monthShort] => Aug
[daysInMonth] => 31
[year] => 2008
[yearShort] => 08
)
)
From the above array, we can get all the details of last 12 months.
hope that this will helpful for you guys.
happy PHPing
I wish, you guys, please comment about this post in following box.
2 comments
Its really useful ,Thanks a lot :)
Post a Comment
Please put your comments here. your questions, your suggestions, also what went wrong with me.