Difference between revisions of "Age"

From Sega Retro

(total rewrite)
Line 1: Line 1:
<includeonly>{{clearvar|dateisvague}}{{#vardefine:date2|{{#if:{{{2|}}}|{{{2|}}}|{{CURRENTYEAR}}-{{CURRENTMONTH}}-{{CURRENTDAY}}}}}}{{#vardefine:date1y|{{#sub:{{#explode:{{{1|}}}|-|0}}|0|4}}}}{{#if:{{#pos:{{#var:date1y}}|x}}
+
<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:dateisvague|true}}{{#vardefine:date1ymin|{{#replace:{{#var:date1y}}|x|0}}}}{{#vardefine:date1ymax|{{#replace:{{#var:date1y}}|x|9}}}}
+
| {{#vardefine:date1ymin|{{#replace:{{#var:date1y}}|x|0}}}}{{#vardefine:date1ymax|{{#replace:{{#var:date1y}}|x|9}}}}
| {{#vardefine:date1ymin|{{#var:date1y}}}}{{#vardefine:date1ymax|{{#var:date1y}}}}}}{{#vardefine:date1m|{{#replace:{{#sub:{{#explode:{{{1|}}}|-|1}}|0|2}}|x}}}}{{#if:{{#var:date1m}}
+
| {{#vardefine:date1ymin|{{#var:date1y}}}}{{#vardefine:date1ymax|{{#var:date1y}}}}
 +
}}{{#vardefine:date1m|{{#replace:{{#sub:{{#explode:{{{1|}}}|-|1}}|0|2}}|x}}}}{{#if:{{#var:date1m}}
 
| {{#vardefine:date1mmin|{{#var:date1m}}}}{{#vardefine:date1mmax|{{#var:date1m}}}}
 
| {{#vardefine:date1mmin|{{#var:date1m}}}}{{#vardefine:date1mmax|{{#var:date1m}}}}
| {{#vardefine:dateisvague|true}}{{#vardefine:date1mmin|01}}{{#vardefine:date1mmax|12}}}}{{#vardefine:date1d|{{#replace:{{#sub:{{#explode:{{{1|}}}|-|2}}|0|2}}|x}}}}{{#if:{{#var:date1d}}
+
| {{#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|{{#var:date1d}}}}{{#vardefine:date1dmax|{{#var:date1d}}}}
| {{#vardefine:dateisvague|true}}{{#vardefine:date1dmin|01}}{{#vardefine:date1dmax|31}}}}{{#if:{{#var:dateisvague}}
+
| {{#vardefine:date1dmin|01}}{{#vardefine:date1dmax|31}}}}{{#if:{{#pos:{{#var:date2y}}|x}}
| {{#vardefine:age1|{{age/CalcAge|{{#var:date1ymax}}-{{#var:date1mmax}}-{{#var:date1dmax}}|{{#var:date2}}}}}}{{#vardefine:age2|{{age/CalcAge|{{#var:date1ymin}}-{{#var:date1mmin}}-{{#var:date1dmin}}|{{#var:date2}}}}}}{{#ifeq:{{#var:age1}}|{{#var:age2}}
+
| {{#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}}
 +
| {{#vardefine:date2dmin|{{#var:date2d}}}}{{#vardefine:date2dmax|{{#var:date2d}}}}
 +
| {{#vardefine:date2dmin|01}}{{#vardefine:date2dmax|31}}
 +
}}{{#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}}
 
| {{#var:age1}}
| {{#if:{{{highonly|}}}||{{#var:age1}}}}{{#if:{{{lowonly|}}}{{{highonly|}}}||-}}{{#if:{{{lowonly|}}}||{{#var:age2}}}}}}
+
| {{#if:{{{highonly|}}}||{{#var:age1}}}}{{#if:{{{lowonly|}}}{{{highonly|}}}||-}}{{#if:{{{lowonly|}}}||{{#var:age2}}}}
| {{age/CalcAge|{{#var:date1y}}-{{#var:date1m}}-{{#var:date1d}}|{{#var:date2}}}}
 
 
}}</includeonly><noinclude>
 
}}</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).
Line 18: Line 27:
 
* <nowiki>{{age|1999-xx-xx}}</nowiki> = {{age|1999-xx-xx}}
 
* <nowiki>{{age|1999-xx-xx}}</nowiki> = {{age|1999-xx-xx}}
 
* <nowiki>{{age|199x}}</nowiki> = {{age|199x}}
 
* <nowiki>{{age|199x}}</nowiki> = {{age|199x}}
 +
* <nowiki>{{age|199x|2000}}</nowiki> = {{age|199x|2000}}
 
* <nowiki>{{age|199x|lowonly=yes}}</nowiki> = {{age|199x|lowonly=yes}}
 
* <nowiki>{{age|199x|lowonly=yes}}</nowiki> = {{age|199x|lowonly=yes}}
 
* <nowiki>{{age|199x|highonly=yes}}</nowiki> = {{age|199x|highonly=yes}}
 
* <nowiki>{{age|199x|highonly=yes}}</nowiki> = {{age|199x|highonly=yes}}

Revision as of 11:40, 22 March 2019

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