I recently needed to add in a credit card expiration date year selector, and just wanted to share the code I used to populate the options. As always, please use this as you see fit.
function ExpYear(){ //Get today's Year $curYear = date("Y"); //Just in case it's needed, get 2 years ago $sYear = $curYear - 2; //Now let's add 10 years $eYear = $curYear + 10; $ret = ''; //For $1 = 2 years ago, to 10 years from now, increment 1 year and populate our return variable for($i = $sYear; $i < $eYear; ++$i){ $ret .= '<option value="' . $i . '">' . $i . '</option>'; } return $ret; }