Kevin Pirnie' Articles

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;

Kevin Pirnie

20+ Years of PC and server maintenance & over 15+ years of web development/design experience; you can rest assured that I take every measure possible to ensure your computers are running to their peak potentials. I treat them as if they were mine, and I am quite a stickler about keeping my machines up to date and optimized to run as well as they can.