Skip to content

Instantly share code, notes, and snippets.

@jenkoian
Created July 28, 2011 12:44
Show Gist options
  • Save jenkoian/1111470 to your computer and use it in GitHub Desktop.
Save jenkoian/1111470 to your computer and use it in GitHub Desktop.
Some useful functions for use with dates
<?php
// Get array of months - useful for month dropdown for example
function getmonths() {
$months = array();
for ($m=1; $m<=12; $m++) {
$months[] = date('m', mktime(0,0,0,$m,1));
}
return $months;
}
// Get array of years - useful for year dropdown for example
function getYears() {
$years = array();
$cutoff = 1910;
$now = date("Y");
for ($y=$now; $y>=$cutoff; $y--) {
$years[] = $y;
}
return $years;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment