Template talk:Age in years

Discussion of proposed change to make this template more accurate
I have been adding error-checking code to age-related templates (see ) recently. As part of that work, I have found a few templates that do not do math correctly, so I have been fixing them. I fixed this "Age in years" template to correct the way it displays ages. That change has been reverted.

At present, since my change has been reverted, the template says that someone born in 2000 is currently 15 years old (in 2015), but that is obviously not correct. Someone born in 2000 is currently either 15 years old (if they have already had a birthday this year) or 14 years old (if they have not yet had a birthday this year).

The code in the sandbox corrects this math problem. Here's the existing template, as it has existed (with incorrect math) for a while:

yields 0 years. yields 0 years.

Here's the code in the sandbox:

yields. yields.

The display of this age shows in the same manner as birth year and age and death year and age, as in the following examples:

This template is primarily used in articles about people. This template is used by Death date and age, which is now displaying ages at death inaccurately in articles such as George Wythe.

I would like to reapply this simple and logical math fix to this template so that it is accurate and in line with other age calculation templates where the exact start date is uncertain. – Jonesey95 (talk) 02:00, 19 April 2015 (UTC)


 * Agree - Seems a reasonable change to correct the wrong display. MilborneOne (talk) 07:03, 19 April 2015 (UTC)


 * The documentation does say "This template should not be used for ages of humans or animals.". I wonder if there are inanimate articles where a date range is undesirable, and maybe we should create a new template for use with humans and animals? Periglio (talk) 12:41, 19 April 2015 (UTC)
 * I wrote that documentation yesterday, since the template is not accurate for the reasons explained above. If the sandbox code is changed, I would remove that bit of documentation. Age specifically returns full years only (and has since its creation in 2007); that template should be used for inanimate objects.
 * As I have said on other Talk pages, the age/birth/death templates need an overhaul, but in the meantime, this template, which is used in 600+ articles, the vast majority of which are about humans, should show accurate ages. – Jonesey95 (talk) 14:03, 19 April 2015 (UTC)
 * Good answer. Quickly scanning through the where used list, I found none where the use was non-biographical. Therefore, I agree with the change in order to keep the age accurate and consistent with the rest of the Wikipedia templates.

Negative years
In List of Justices of the Supreme Court of the United States, the Age in Years template is used to get the length of time a person was on the US Supreme Court. One Justice served less than a year, and the code " 0 years " shows up as "–0". Should the template check for the special case of start year = end year, and say something like "< 1 year"? --ΨΦorg (talk) 19:34, 1 June 2015 (UTC)
 * That table looks awkward with those year ranges. I would use Age instead, which gives you a whole number of years. That said, I'll see if I can add a statement to this template to test for the two parameters being equal and output a zero. – Jonesey95 (talk) 02:03, 2 June 2015 (UTC)

I added code to check for zero ages, as well as code to display an error message for negative ages.

Examples using new code in the sandbox:


 * &rarr;
 * &rarr;
 * &rarr;
 * &rarr;
 * &rarr;

Are there any objections to moving this sandbox code to the template? – Jonesey95 (talk) 03:55, 2 June 2015 (UTC)


 * And testing/fixing a template that transcludes this one:
 * &rarr; December 15, 1911
 * &rarr;
 * &rarr; December 15, 2010
 * &rarr;


 * That looks like an improvement. There is a redundant error message, but I'm not interested in coding for that. – Jonesey95 (talk) 04:14, 2 June 2015 (UTC)
 * Good work, I say go for it! Periglio (talk) 04:26, 2 June 2015 (UTC)


 * Done. – Jonesey95 (talk) 05:02, 2 June 2015 (UTC)