Quick PHP year Select Populator

Quick PHP year Select Populator

Quick PHP year Select Populator

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;
}

Categories


Let Us Help

Get You Online

Contact Us Today

Important Cookie Information
Our website uses cookies. By continuing to browse the site you are agreeing to our use of cookies. For more details about cookies and their use, please see our Cookie Policy.