HXH
HXH
May 3, 2010
  3279
(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
Plug-in manager is back in CMS 12

Plug-in manager is back in the UI, what is it and how can i use it?

Luc Gosso (MVP) | Oct 6, 2022 | Syndicated blog

Display Child Pages in Content Delivery API Response

The below example will implement an instance of IContentConverterProvider to customise the serialisation of PageData and output child pages in the...

Minesh Shah (Netcel) | Oct 4, 2022

Bring the Report Center back in Optimizely CMS 12

The Report Center has been a part of Optimizely CMS since its first debut in version 5R2 in 2008, but in CMS 12, it's removed! Don't despair! Make...

Tomas Hensrud Gulla | Oct 4, 2022 | Syndicated blog

Customizing Property Lists in Optimizely CMS

Generic property lists is a cool editorial feature that has gained a lot of popularity - in spite of still being unsupported (officially). But if y...

Allan Thraen | Oct 2, 2022 | Syndicated blog