5

I use Date module in D7, and I create new field "decade" (field type is Date). Also in the settings, I add a custom input format 'Y' (only years). There is increment for time (+/-30 minutes), but I need increments for years (+/- 10 year). In node add form I need selectbox with values like:

1700
1710
1720
1730
....
now

How can I do that?

2
  • 2
    With a 10 year granularity you are obviously not placing these dates in a calendar. Are you doing any math or date comparisons, or are you simply cataloging history by decade? How are you using this information?
    – Triskelion
    Commented Mar 12, 2013 at 7:09
  • 1
    Do you need this to be a date field? If you store it as an integer you can manually define the select options (1700, 1710, etc). Overriding options on node entities gets hairy. Even the best solutions often don't take into account translations. Commented Mar 12, 2013 at 9:29

1 Answer 1

-1

You shouldn't use a date format for your field

I advice you to use CCK module (7.x-2.x-dev)

some miscellaneous helpers to do things that core will not do, like maintain the PHP code snippets some fields may have been using to define allowed values (partially working)

With this module, you define these kind of allowed values from a php code

3
  • CCK module has nothing to do with date field or the question itself.
    – Aboodred1
    Commented Mar 14, 2013 at 20:53
  • @Aboodred1 a "decade" is not really a date, also a decade can be a list of options, and a php methog returning a list of allowed options is an alternative solution with dynamic content based on current year. $options = array(); $min = 1700; $max = intval( date( 'Y', time() ) / 10) * 10; for ($i = $min; $i <= $max; $i+=10){ $options[] = $i; }
    – pico34
    Commented Mar 15, 2013 at 9:33
  • I hear you. I guess you need to put your comment as part of your answer.
    – Aboodred1
    Commented Mar 15, 2013 at 14:46

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.