Wondering how I would use either EE or PHP to dynamically generate a list of years starting from this year. I'm doing this for a credit card expiry select box that needed to use EE global variables for the label, which is why i couldn't just use the fields spit back from the gateway. And of course their example code is just a static list starting with 2012, so I'd rather the list be dynamic for say 10 years starting this year. Can someone tell me how to do this?

2 Answers 2


Assuming PHP is enabled in your template, this should get you started...

<select name="credit-card-expiration-year" id="credit-card-expiration-year">
   for($i = date("Y"); $i < date("Y")+10; $i++){
     echo "<option>" . $i . "</option>";
  • I certain CAN enable PHP in the template. Is that the most effective way to handle it? I didn't figure there was an easy way to do it with EE tags. Dec 7, 2012 at 21:15

I wrote a simple plugin to do this and you can also use this plugin (I did not write rangee): http://devot-ee.com/add-ons/rangee

  • Awesome. I didn't know about rangee - have bookmarked for future projects.
    – CreateSean
    Dec 7, 2012 at 21:33
  • Very cool - I hadn't known about rangee either Dec 7, 2012 at 22:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.