Skip to content

Instantly share code, notes, and snippets.

@jrmadsen67
Created March 6, 2013 06:25
Show Gist options
  • Save jrmadsen67/5097167 to your computer and use it in GitHub Desktop.
Save jrmadsen67/5097167 to your computer and use it in GitHub Desktop.
Get preceding 12 month array, starting with 12 months earlier and ending in current month (ex. Today is Mar, so array will be Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec,Jan,Feb,Mar)
$date = new DateTime((date('Y')-1).'-'.date('m').'-01' ); //to kill the 31 day problem
$months_array = array_map(function($val) use ($date) {return $date->add(new DateInterval('P1M'))->format('M');}, range(1,12));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment