Template:Age in years, months and days/doc
{{#switch:<translate></translate> | = {{#if:{{#ifexpr: ( {{#ifeq:doc|doc|1|0}} or ( {{#ifeq:{{#titleparts:template:age in years, months and days/doc|-1|-2}}|doc|1|0}} and {{#if:{{#translation:}}|1|0}} ) )|1|}}
|
{{#ifeq:show |show
| TemplateStyles' src
attribute must not be empty.
File:OOjs UI icon book-ltr.svg | <translate> This is a documentation [[<tvar name=2>Special:MyLanguage/Help:Subpages</tvar>|subpage]] for <tvar name=1>Template:Age in years, months and days</tvar>.</translate> {{#if: |<translate> It contains usage information, [[<tvar name=7>Special:MyLanguage/Help:Categories</tvar>|categories]] and other content that is not part of the original <tvar name=1>{{{text1}}}</tvar>.</translate> |<translate> It contains usage information, [[<tvar name=7>Special:MyLanguage/Help:Categories</tvar>|categories]] and other content that is not part of the original <tvar name=1>Template</tvar> page.</translate>}} |
}}{{#if: | | {{#ifexist:Template:Age in years, months and days | [[Category:{{#switch:Template | Template | Project = Template | Module = Module | User = User | #default = MediaWiki }} documentation pages{{#translation:}}]] | [[Category:Documentation subpages without corresponding pages{{#translation:}}]] }} }} | }}
| #default=
{{#switch:
| = {{#if:{{#ifexpr: ( {{#ifeq:doc|doc|1|0}} or ( {{#ifeq:{{#titleparts:template:age in years, months and days/doc|-1|-2}}|doc|1|0}} and {{#if:{{#translation:}}|1|0}} ) )|1|}}
|
{{#ifeq:show |show
| TemplateStyles' src
attribute must not be empty.
File:OOjs UI icon book-ltr.svg | This is a documentation subpage for Template:Age in years, months and days. {{#if: |It contains usage information, categories and other content that is not part of the original {{{text1}}}. |It contains usage information, categories and other content that is not part of the original Template page.}} |
}}{{#if: | | {{#ifexist:Template:Age in years, months and days | [[Category:{{#switch:Template | Template | Project = Template | Module = Module | User = User | #default = MediaWiki }} documentation pages{{#translation:}}]] | [[Category:Documentation subpages without corresponding pages{{#translation:}}]] }} }} | }}
| #default=
Lua error: expandTemplate: template loop detected.
}} }} {{#switch:<translate></translate> | =
TemplateStyles' src
attribute must not be empty.
File:OOjs UI icon alert-warning.svg | {{#switch:Template
|Module={{#if: |<translate> This Lua module is used on approximately <tvar name=5>{{{1}}}</tvar> pages.</translate> |<translate> This Lua module is used on many pages.</translate> }} |#default={{#if: |<translate> This template is used on approximately <tvar name=5>{{{1}}}</tvar> pages.</translate> |<translate> This template is used on many pages.</translate> }} }} {{#switch:Template |Module=<translate> To avoid large-scale disruption and unnecessary server load, any changes to this module should first be tested in its [[<tvar name=4>{{#switch:doc|doc|sandbox=Template:Age in years, months and days|#default=Template:Age in years, months and days/doc}}/sandbox</tvar>|/sandbox]] or [[<tvar name=5>{{#switch:doc|doc|sandbox=Template:Age in years, months and days|#default=Template:Age in years, months and days/doc}}/testcases</tvar>|/testcases]] subpages.</translate> |#default=<translate> To avoid large-scale disruption and unnecessary server load, any changes to this template should first be tested in its [[<tvar name=4>{{#switch:doc|doc|sandbox=Template:Age in years, months and days|#default=Template:Age in years, months and days/doc}}/sandbox</tvar>|/sandbox]] or [[<tvar name=5>{{#switch:doc|doc|sandbox=Template:Age in years, months and days|#default=Template:Age in years, months and days/doc}}/testcases</tvar>|/testcases]] subpages or in your own [[<tvar name=9>Special:MyLanguage/Help:Subpages#Use of subpages</tvar>|user subpage]].</translate> }} <translate> The tested changes can then be added to this page in one single edit.</translate> {{#if: |<translate> Please consider discussing any changes at <tvar name=2>[[Template:Trim]]</tvar> before implementing them.</translate> |<translate> Please consider discussing any changes on the [[<tvar name=3>{{#switch:doc|doc|sandbox=Template talk:Age in years, months and days|#default=Template talk:Age in years, months and days/doc}}</tvar>|talk page]] before implementing them.</translate>}} |
| #default=
{{#switch:
| =
TemplateStyles' src
attribute must not be empty.
File:OOjs UI icon alert-warning.svg | {{#switch:Template
|Module={{#if: |This Lua module is used on approximately {{{1}}} pages. |This Lua module is used on many pages. }} |#default={{#if: |This template is used on approximately {{{1}}} pages. |This template is used on many pages. }} }} {{#switch:Template |Module=To avoid large-scale disruption and unnecessary server load, any changes to this module should first be tested in its [[{{#switch:doc|doc|sandbox=Template:Age in years, months and days|#default=Template:Age in years, months and days/doc}}/sandbox|/sandbox]] or [[{{#switch:doc|doc|sandbox=Template:Age in years, months and days|#default=Template:Age in years, months and days/doc}}/testcases|/testcases]] subpages. |#default=To avoid large-scale disruption and unnecessary server load, any changes to this template should first be tested in its [[{{#switch:doc|doc|sandbox=Template:Age in years, months and days|#default=Template:Age in years, months and days/doc}}/sandbox|/sandbox]] or [[{{#switch:doc|doc|sandbox=Template:Age in years, months and days|#default=Template:Age in years, months and days/doc}}/testcases|/testcases]] subpages or in your own user subpage. }} The tested changes can then be added to this page in one single edit. {{#if: |Please consider discussing any changes at [[Template:Trim]] before implementing them. |Please consider discussing any changes on the [[{{#switch:doc|doc|sandbox=Template talk:Age in years, months and days|#default=Template talk:Age in years, months and days/doc}}|talk page]] before implementing them.}} |
| #default=
Lua error: expandTemplate: template loop detected.
}} }}
TemplateStyles' src
attribute must not be empty.
Lua logo | Uses Lua: |
This template returns the number of full years, then surplus months, then surplus days between two specified dates. If the second set of parameters is not included, it will return the number of years, months and days between a specified date and today's date. The words "year", "month" and "day" are plural when appropriate.
The years and months are separated by a comma. Since serial commas are optional and use varies, this template does not automatically place a comma after the months. If a serial comma is desired, adding |{{SAFESUBST:#if:sc|sc=}}y
to the template invocation will include one.
See Wikipedia:Age calculation templates for more information on using this kind of template.
Usage
{{Age in years, months and days|year= |month= |day= }}
or{{Age in years, months and days|yyyy|mm|dd|yyyy2|mm2|dd2}}
Examples
{{Age in years, months and days|year=2001|month=1|day=15}}
returns "24 years and 5 months"{{Age in years, months and days|2001|01|15|2008|09|05}}
returns "7 years, 7 months and 21 days"{{Age in years, months and days|2016|8|4|2016|9|5}}
returns "1 month and 1 day"
Notes
This template can handle an ambiguous start date:
{{Age in years, months and days|year=2010|month=9}}
returns "14 years and 8 or 9 months"{{Age in years, months and days|2009|6||2011|2|21}}
returns "1 year and 7 or 8 months"
But it cannot handle an ambiguous end date:
{{Age in years, months and days|2012|11|2|2016|4}}
returns "3 years and 4 or 5 months"{{Age in years, months and days|2012|11|2|2017}}
returns "4 or 5 years"
Since the length of a month varies, the number of days to roll over the number of months varies.
{{Age in years, months and days|2007|3|12|2015|6|11}}
returns "8 years, 2 months and 30 days"{{Age in years, months and days|2007|3|12|2015|7|11}}
returns "8 years, 3 months and 29 days"
To add a serial comma specify |{{SAFESUBST:#if:sc|sc=}}y
.
{{Age in years, months and days|year=2001|month=1|day=15|sc=y}}
returns "24 years and 5 months"{{Age in years, months and days|2001|1|15|2008|9|5|sc=y}}
returns "7 years, 7 months, and 21 days"{{Age in years, months and days|{{#ifexpr:{{#time:z|June 15}}<14|{{#expr:2025-8}}|{{#ifexpr:{{#time:z|June 15}}<45|2006|{{#expr:2025-8}}}}}}|{{#ifexpr:{{#time:z|June 15}}<14|12|{{#ifexpr:{{#time:z|June 15}}<45|8|{{#ifexpr:15<15|{{#expr:06-1}}|06}}}}}}|{{#ifexpr:{{#time:z|June 15}}<14|{{#ifexpr:15<15|{{#expr:15+15}}|{{#expr:15-14}}}}|{{#ifexpr:{{#time:z|June 15}}<4|4|{{#ifexpr:15<15|{{#expr:15+15}}|{{#expr:15-14}}}}}}}}|sc=y}}
returns "Error: Need valid year, month, day"
TemplateData
{{#switch:<translate></translate> |=
|no |n |false |0 = | = |¬ = |yes |y |true |1 = yes |#default = yes
}}|{{#ifexpr:{{#if:|{{#ifeq:Template:Age in years, months and days/doc|{{#switch:
|#default = | = {{#ifeq: | | Template:{{{docpage}}} | }}
}}|0|1}}|not{{#ifexpr: ( {{#ifeq:doc|doc|1|0}} or ( {{#ifeq:{{#titleparts:template:age in years, months and days/doc|-1|-2}}|doc|1|0}} and {{#if:{{#translation:}}|1|0}} ) )|1|0}}}}|
|#default = Age in years, months and days/doc | = {{#ifeq: | | Template:Age in years, months and days/doc | Age in years, months and days/doc }}
}}|<span style="" title="<translate nowrap> View this template</translate>">{{#if:|<translate> v</translate>|<translate> view</translate>}}]] · [[[:Template:Fullurl:]] <span style="" title="<translate nowrap> Discuss this template</translate>">{{#if:|<translate> d</translate>|<translate> talk</translate>}}]{{#if:|| · [{{fullurl:{{#switch:
|#default = Age in years, months and days/doc | = {{#ifeq: | | Template:Age in years, months and days/doc | Age in years, months and days/doc }}
}}|action=edit}} <span style="" title="<translate nowrap> Edit this template</translate>">{{#if:|<translate> e</translate>|<translate> edit</translate>}}]}}{{#if:1|]}}}}}} {{#if:||<translate> This is the [[<tvar name=1>Special:MyLanguage/Help:TemplateData</tvar>|TemplateData]] documentation for this template used by [[<tvar name=2>Special:MyLanguage/VisualEditor</tvar>|VisualEditor]] and other tools.</translate>}}
Age in years, months and days
{{#ifeq:doc|sandbox||{{#if:{{#ifexpr: (
{{#ifeq:doc|doc|1|0}} or ( {{#ifeq:{{#titleparts:template:age in years, months and days/doc|-1|-2}}|doc|1|0}} and {{#if:{{#translation:}}|1|0}} ) )|1|}}|[[Category:TemplateData documentation{{#translation:}}]]|[[Category:Templates using TemplateData{{#translation:}}]]}}}} | #default=
{{#switch:
|=
|no |n |false |0 = | = |¬ = |yes |y |true |1 = yes |#default = yes
}}|{{#ifexpr:{{#if:|{{#ifeq:Template:Age in years, months and days/doc|{{#switch:
|#default = | = {{#ifeq: | | Template:{{{docpage}}} | }}
}}|0|1}}|not{{#ifexpr: ( {{#ifeq:doc|doc|1|0}} or ( {{#ifeq:{{#titleparts:template:age in years, months and days/doc|-1|-2}}|doc|1|0}} and {{#if:{{#translation:}}|1|0}} ) )|1|0}}}}|
|#default = Age in years, months and days/doc | = {{#ifeq: | | Template:Age in years, months and days/doc | Age in years, months and days/doc }}
}}|<span style="" title="<translate nowrap> View this template</translate>">{{#if:|<translate> v</translate>|<translate> view</translate>}}]] · [[[:Template:Fullurl:]] <span style="" title="<translate nowrap> Discuss this template</translate>">{{#if:|<translate> d</translate>|<translate> talk</translate>}}]{{#if:|| · [{{fullurl:{{#switch:
|#default = Age in years, months and days/doc | = {{#ifeq: | | Template:Age in years, months and days/doc | Age in years, months and days/doc }}
}}|action=edit}} <span style="" title="<translate nowrap> Edit this template</translate>">{{#if:|<translate> e</translate>|<translate> edit</translate>}}]}}{{#if:1|]}}}}}} {{#if:||This is the TemplateData documentation for this template used by VisualEditor and other tools.}}
Age in years, months and days
{{#ifeq:doc|sandbox||{{#if:{{#ifexpr: (
{{#ifeq:doc|doc|1|0}} or ( {{#ifeq:{{#titleparts:template:age in years, months and days/doc|-1|-2}}|doc|1|0}} and {{#if:{{#translation:}}|1|0}} ) )|1|}}|[[Category:TemplateData documentation{{#translation:}}]]|[[Category:Templates using TemplateData{{#translation:}}]]}}}} | #default=
Lua error: expandTemplate: template loop detected.
}} }}
This template returns the number of full years, surplus months, and surplus days between two specified dates. If the second set of parameters is not included, it will return the number of years, months and days between a specified date and today's date.
Parameter | Description | Type | Status | |
---|---|---|---|---|
Year ('from' date) | 1 year | The year of the (first) date | Number | required |
Month ('from' date) | 2 month | Number of the month of the (first) date | Number | required |
Day of month ('from' date) | 3 day | The day of the month of the (first) date | Number | optional |
Year ('to' date) | 4 | The year of the 'to' date, if required
| Number | optional |
Month ('to' date) | 5 | Number of the month of the 'to' date, if required
| Number | optional |
Day of month ('to' date) | 6 | The day of the month of the 'to' date, if required
| Number | optional |
Serial comma | sc | Enter 'y' to turn on the serial comma after the months
| Line | optional |
See also
- Wikipedia:Age calculation templates
- {{{{#ifeq:Template:User Wikipedian for|
|
}}[[Special:MyLanguage/Template:User Wikipedian for|{{#if: |{{{2}}} |{{#ifexist:Translations:{{#if:Template|Template:}}User Wikipedian for/Page display title/en
|{{#ifexpr:{{#if:0|1|0}} and 10!=0 |{{#ifeq:en|en |User Wikipedian for |{{#if: |{{#ifeq:0|0 | | String Module Error: Target string is empty }} |{{#if:{{ Template:TNTN | nsp = 0 }} |{{ Template:TNTN | nsp = 0 }} |Template:User Wikipedian for }} }} }} |{{ Template:TNTN }} }} |{{#if:0 |{{#if:User Wikipedian for |User Wikipedian for |Template:User Wikipedian for }} |Template:User Wikipedian for }}
}}}}]]{{#ifeq:Template:User Wikipedian for|
|
}}
}}- {{{{#ifeq:Template:User admin since|
|
}}[[Special:MyLanguage/Template:User admin since|{{#if: |{{{2}}} |{{#ifexist:Translations:{{#if:Template|Template:}}User admin since/Page display title/en
|{{#ifexpr:{{#if:0|1|0}} and 10!=0 |{{#ifeq:en|en |User admin since |{{#if: |{{#ifeq:0|0 | | String Module Error: Target string is empty }} |{{#if:{{ Template:TNTN | nsp = 0 }} |{{ Template:TNTN | nsp = 0 }} |Template:User admin since }} }} }} |{{ Template:TNTN }} }} |{{#if:0 |{{#if:User admin since |User admin since |Template:User admin since }} |Template:User admin since }}
}}}}]]{{#ifeq:Template:User admin since|
|
}}
}}