HXH
HXH
May 3, 2010
visibility 4283
star star star star star
(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

error Please login to comment.
Latest blogs
Migrate Optimizely DAM Assets from CMS 12 to CMS 13

Sites that used Optimizely DAM in CMS 12 need their asset references moved to the new Graph-backed content sources after upgrading. CMS 13.3 includ...

Bartosz Sekula | Oct 6, 2026

Scheduler Delegation: Using Optimizely DXP Infrastructure for Queued Processing

At SYZYGY Techsolutions, we support Optimizely DXP projects at scale, so continuously identifying unique ways to optimize the application is an...

Mike | Oct 6, 2026

Thomas in the AI Discovery Era

Its been a while, but hope you haven't forgotten Thomas, our most loyal visitor, the one who suddenly stops showing up. Not because he lost interes...

Ritu Madan | Oct 6, 2026

Optimizely Agent Platform - October 2026 State of Play

Overview A month ago I wrote up my takeaways from Opticon New York ( Opticon New York & The Strategy on Upgrading to CMS 13 & Commerce 15 ). The...

Scott Reed | Oct 5, 2026