Topic on Help talk:Extension:ParserFunctions

If 1979, create category 1970s

3
AmeliaLH (talkcontribs)

Hi! I'm sorry if this is a stupid question but numbers tend to hurt my brain. On my wiki, I have a template that generates links to specific dates based off three parameters, month, day, and year. However, I want the <code>year</code> field to generate a category for the decade that year is apart of. For example Jan|17|1979 should generate the category, 1970. I feel like this can be done via #expr somewhere but it's going over my head.

Any help would be appreciated.

Aidan9382 (talkcontribs)

If I'm not mistaken, it sounds like something like {{#expr:1979-(1979 mod 10)}} or {{#expr:floor(1979/10)*10}} would do what you are asking for. There may be a simpler solution, but its not coming to my head right now, so hopefully this'll do.

Dinoguy1000 (talkcontribs)

If you have access to stringfunctions, {{ #sub: 1979 | 0 | 3 }}0 will also work. (If you need it to work on years that aren't four digits long, you can manage it by replacing the "3" with {{ #expr: {{ #len: 1979 }} - 1 }}, but by that point you might as well just use one of Aidan's #expr suggestions.)

Reply to "If 1979, create category 1970s"