Difference between revisions of "Age"
From Sega Retro
m (Text replacement - "Category:Sega Retro templates" to "Category:Templates") |
|||
(4 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
− | <includeonly>{{#if: {{{2|}}} | + | <includeonly>{{#vardefine:date2|{{#if:{{{2|}}}|{{{2|}}}|{{CURRENTYEAR}}-{{CURRENTMONTH}}-{{CURRENTDAY}}}}}}{{#vardefine:date1y|{{#sub:{{#explode:{{{1|}}}|-|0}}|0|4}}}}{{#vardefine:date2y|{{#sub:{{#explode:{{#var:date2}}|-|0}}|0|4}}}}{{#if:{{#pos:{{#var:date1y}}|x}} |
− | | {{#vardefine: | + | | {{#vardefine:date1ymin|{{#replace:{{#var:date1y}}|x|0}}}}{{#vardefine:date1ymax|{{#replace:{{#var:date1y}}|x|9}}}} |
− | + | | {{#vardefine:date1ymin|{{#var:date1y}}}}{{#vardefine:date1ymax|{{#var:date1y}}}} | |
− | }}{{#vardefine: | + | }}{{#vardefine:date1m|{{#replace:{{#sub:{{#explode:{{{1|}}}|-|1}}|0|2}}|x}}}}{{#if:{{#var:date1m}} |
− | | {{#vardefine: | + | | {{#vardefine:date1mmin|{{#var:date1m}}}}{{#vardefine:date1mmax|{{#var:date1m}}}} |
− | + | | {{#vardefine:date1mmin|01}}{{#vardefine:date1mmax|12}} | |
− | + | }}{{#vardefine:date1d|{{#replace:{{#sub:{{#explode:{{{1|}}}|-|2}}|0|2}}|x}}}}{{#if:{{#var:date1d}} | |
− | }}{{# | + | | {{#vardefine:date1dmin|{{#var:date1d}}}}{{#vardefine:date1dmax|{{#var:date1d}}}} |
− | | {{# | + | | {{#vardefine:date1dmin|01}}{{#vardefine:date1dmax|31}}}}{{#if:{{#pos:{{#var:date2y}}|x}} |
− | + | | {{#vardefine:date2ymin|{{#replace:{{#var:date2y}}|x|0}}}}{{#vardefine:date2ymax|{{#replace:{{#var:date2y}}|x|9}}}} | |
− | + | | {{#vardefine:date2ymin|{{#var:date2y}}}}{{#vardefine:date2ymax|{{#var:date2y}}}} | |
− | + | }}{{#vardefine:date2m|{{#replace:{{#sub:{{#explode:{{#var:date2}}|-|1}}|0|2}}|x}}}}{{#if:{{#var:date2m}} | |
− | + | | {{#vardefine:date2mmin|{{#var:date2m}}}}{{#vardefine:date2mmax|{{#var:date2m}}}} | |
− | + | | {{#vardefine:date2mmin|01}}{{#vardefine:date2mmax|12}} | |
− | + | }}{{#vardefine:date2d|{{#replace:{{#sub:{{#explode:{{#var:date2}}|-|2}}|0|2}}|x}}}}{{#if:{{#var:date2d}} | |
− | }}{{#ifeq: {{#var: | + | | {{#vardefine:date2dmin|{{#var:date2d}}}}{{#vardefine:date2dmax|{{#var:date2d}}}} |
− | | {{# | + | | {{#vardefine:date2dmin|01}}{{#vardefine:date2dmax|31}} |
− | }}{{#var: | + | }}{{#vardefine:age1|{{age/CalcAge|{{#var:date1ymax}}-{{#var:date1mmax}}-{{#var:date1dmax}}|{{#var:date2ymin}}-{{#var:date2mmin}}-{{#var:date2dmin}}}}}}{{#vardefine:age2|{{age/CalcAge|{{#var:date1ymin}}-{{#var:date1mmin}}-{{#var:date1dmin}}|{{#var:date2ymax}}-{{#var:date2mmax}}-{{#var:date2dmax}}}}}}{{#ifeq:{{#var:age1}}|{{#var:age2}} |
+ | | {{#var:age1}} | ||
+ | | {{#if:{{{highonly|}}}||{{#var:age1}}}}{{#if:{{{lowonly|}}}{{{highonly|}}}||-}}{{#if:{{{lowonly|}}}||{{#var:age2}}}} | ||
+ | }}</includeonly><noinclude> | ||
Convert a date in the format YYYY-MM-DD to an age in years (based on the current date). | Convert a date in the format YYYY-MM-DD to an age in years (based on the current date). | ||
==Usage== | ==Usage== | ||
− | + | * <nowiki>{{age|1991-06-23}}</nowiki> = {{age|1991-06-23}} | |
− | + | * <nowiki>{{age|1991}}</nowiki> = {{age|1991}} | |
− | + | * <nowiki>{{age|1999-xx-xx}}</nowiki> = {{age|1999-xx-xx}} | |
− | + | * <nowiki>{{age|199x}}</nowiki> = {{age|199x}} | |
− | {{age| | + | * <nowiki>{{age|199x|2000}}</nowiki> = {{age|199x|2000}} |
+ | * <nowiki>{{age|199x|lowonly=yes}}</nowiki> = {{age|199x|lowonly=yes}} | ||
+ | * <nowiki>{{age|199x|highonly=yes}}</nowiki> = {{age|199x|highonly=yes}} | ||
===Optional parameter=== | ===Optional parameter=== | ||
Add a second date to calculate the age on that date. | Add a second date to calculate the age on that date. | ||
− | + | * <nowiki>{{age|1991-06-23|1999-09-09}}</nowiki> = {{age|1991-06-23|1999-09-09}} | |
− | |||
− | |||
− | |||
− | {{age|1991-06-23|1999-09-09}} | ||
− | [[Category: | + | [[Category:Templates]]</noinclude> |
Latest revision as of 13:54, 1 January 2022
Convert a date in the format YYYY-MM-DD to an age in years (based on the current date).
Usage
- {{age|1991-06-23}} = 33
- {{age|1991}} = 32-33
- {{age|1999-xx-xx}} = 24-25
- {{age|199x}} = 24-34
- {{age|199x|2000}} = 0-10
- {{age|199x|lowonly=yes}} = 24
- {{age|199x|highonly=yes}} = 34
Optional parameter
Add a second date to calculate the age on that date.
- {{age|1991-06-23|1999-09-09}} = 8