Module:Age range
Jump to navigation
Jump to search
Purpose
[edit source]This module provides a simple way to display an automatically updating age range when only an approximate birth year is known (e.g. "1991/1992"). It is designed to be used when the exact year of birth is uncertain but falls within a known range of two consecutive years.
Usage
[edit source]Invoke the module using:
{{#invoke:Age range|ageRange|<earlier year>|<later year>}}
Example:
Born 1991/1992 (age {{#invoke:Age range|ageRange|1991|1992}})
As of 2026, this would output:
Born 1991/1992 (age 33–34)
Parameters
[edit source]1– The earlier possible year of birth (e.g.1991)2– The later possible year of birth (e.g.1992)
Returns
[edit source]A string in the format:
33if both years produce the same age33–34if the years produce a range of ages
Examples
[edit source]| Wikitext | Output (as of 2026) |
|---|---|
36 |
36 |
34–35 |
34–35 |
40–41 |
40–41 |
See also
[edit source]- Module:Age – for precise age calculation
- Template:Birth date – for exact known birthdates
Notes
[edit source]- This module assumes birth has already occurred this year.
- Does not account for specific months or days.
- Use only when the birth year is narrowed to two possibilities.
Module code
[edit source]See Module:Age range for implementation.
local p = {}
function p.ageRange(frame)
local args = frame.args
local year1 = tonumber(args[1])
local year2 = tonumber(args[2])
local currentYear = tonumber(os.date('%Y'))
if not year1 or not year2 then return '' end
local age1 = currentYear - year2
local age2 = currentYear - year1
if age1 == age2 then
return age1
else
return age1 .. '–' .. age2
end
end
return p