<?php
function _getRollingMonths($months = 12) {
$currentTime = strtotime('2015-01-30');
$dates = array();
for($i=$months-1;$i>=0;$i--) {
$dates[] = array(
'year' => date('Y', strtotime("first day of -$i months", $currentTime)),
'month' => date('m', strtotime("first day of -$i months", $currentTime)),
'monthName' => date('M', strtotime("first day of -$i months", $currentTime))
);
}
return $dates;
}
function _getMonths($year = null) {
if (!isset($year)) {
$year = date('Y');
}
$dates = array();
for($month=1;$month<=12;$month++) {
$dates[] = array(
'year' => date('Y', strtotime("$year-$month-01")),
'month' => date('m', strtotime("$year-$month-01")),
'monthName' => date('M', strtotime("$year-$month-01"))
);
}
return $dates;
}
function _getYTDMonths($year = null) {
if (!isset($year)) {
$year = date('Y');
}
$dates = array();
for($i=date('m')-1;$i>=0;$i--) {
$dates[] = array(
'year' => $year,
'month' => date('m', strtotime("-$i months")),
'monthName' => date('M', strtotime("-$i months"))
);
if (date('m', strtotime("-$i months")) == date('m')) {
$dates[count($dates)-1]['day'] = date('d', strtotime("-$i months"));
}
}
return $dates;
}
function debug($var) {
echo "<pre>";
print_r($var);
echo "</pre>";
}
debug(_getYTDMonths(2015));
preferences:
61.62 ms | 402 KiB | 5 Q