November Happy Hour will be moved to Thursday December 5th.

HXH
HXH
May 3, 2010
  3840
(0 votes)

Creating Dynamic Year Values

I absolutely hate when forms and web sites lack common intelligence. Copyright years should always show the current year. Year Dropdown Lists should always have the most recent values. We’re living in a dynamic world where information is always changing.. there’s no excuse for having static content hard coded into page templates!

I use this little function to get an ArrayList of the current year and the two years previous to it. There’s really nothing to it…. but by calling this, all the “Select a Year” fields on my forms update every year, without a single line of hardcoded values needing to be changed. Ever again.

        public static ArrayList GetAcceptableYears()
        {
            ArrayList AcceptableYears = new ArrayList();

            AcceptableYears.Add(DateTime.Now.Year - 2).ToString();
            AcceptableYears.Add(DateTime.Now.Year - 1).ToString();
            AcceptableYears.Add(DateTime.Now.Year).ToString();

            return AcceptableYears;
        }
May 03, 2010

Comments

Please login to comment.
Latest blogs
Optimizely SaaS CMS + Coveo Search Page

Short on time but need a listing feature with filters, pagination, and sorting? Create a fully functional Coveo-powered search page driven by data...

Damian Smutek | Nov 21, 2024 | Syndicated blog

Optimizely SaaS CMS DAM Picker (Interim)

Simplify your Optimizely SaaS CMS workflow with the Interim DAM Picker Chrome extension. Seamlessly integrate your DAM system, streamlining asset...

Andy Blyth | Nov 21, 2024 | Syndicated blog

Optimizely CMS Roadmap

Explore Optimizely CMS's latest roadmap, packed with developer-focused updates. From SaaS speed to Visual Builder enhancements, developer tooling...

Andy Blyth | Nov 21, 2024 | Syndicated blog

Set Default Culture in Optimizely CMS 12

Take control over culture-specific operations like date and time formatting.

Tomas Hensrud Gulla | Nov 15, 2024 | Syndicated blog

I'm running Optimizely CMS on .NET 9!

It works 🎉

Tomas Hensrud Gulla | Nov 12, 2024 | Syndicated blog

Recraft's image generation with AI-Assistant for Optimizely

Recraft V3 model is outperforming all other models in the image generation space and we are happy to share: Recraft's new model is now available fo...

Luc Gosso (MVP) | Nov 8, 2024 | Syndicated blog