Difference between revisions of "Age"
From Sega Retro
m |
|||
Line 1: | Line 1: | ||
− | <includeonly>{{#if: {{{2|}}} | {{#vardefine:date2_y|{{year|{{{2}}}}}}}{{#vardefine:date2_m|{{month|{{{2}}}}}}}{{#vardefine:date2_d|{{# | + | <includeonly>{{#if: {{{2|}}} |
− | + | | {{#vardefine:date2_y|{{year|{{{2}}}}}}}{{#vardefine:date2_m|{{month|{{{2}}}}}}}{{#vardefine:date2_d|{{#explode:{{{2}}}|-|2}}}} | |
− | }}{{#ifexpr: {{#var:date2_m}} | + | | {{#vardefine:date2_y|{{CURRENTYEAR}}}}{{#vardefine:date2_m|{{CURRENTMONTH}}}}{{#vardefine:date2_d|{{CURRENTDAY}}}} |
− | + | }}{{#vardefine:date1_y|{{year|{{{1}}}}}}}{{#vardefine:date1_m|{{month|{{{1}}}}}}}{{#vardefine:date1_d|{{#explode:{{{1}}}|-|2}}}}{{#if:{{#var:date1_d}}||{{#vardefine:date1_d|01}}}}<!-- Set day to 01 if undefined (for simplicity). -->{{#if:{{#var:date2_d}}||{{#vardefine:date2_d|01}}}}{{#vardefine:age|}}{{#ifexpr: {{#var:date2_m}} > {{#var:date1_m}} | |
− | }}{{#ifexpr: {{#var:date2_m}} = {{ | + | | {{#vardefine:age|{{#expr:{{#var:date2_y}}-{{#var:date1_y}}}}}} |
− | | {{#ifexpr: {{#var:date2_d}} > {{# | + | }}{{#ifexpr: {{#var:date2_m}} < {{#var:date1_m}} |
− | | {{#expr:{{#var:date2_y}}-{{ | + | | {{#vardefine:age|{{#expr:{{#var:date2_y}}-{{#var:date1_y}}-1}}}} |
− | }}{{#ifexpr: {{#var:date2_d}} < {{# | + | }}{{#ifexpr: {{#var:date2_m}} = {{#var:date1_m}} |
− | | {{#expr:{{#var:date2_y}}-{{ | + | | {{#ifexpr: {{#var:date2_d}} > {{#var:date1_d}} |
− | }}{{#ifexpr: {{#var:date2_d}} = {{# | + | | {{#vardefine:age|{{#expr:{{#var:date2_y}}-{{#var:date1_y}}}}}} |
− | | {{#expr:{{#var:date2_y}}-{{ | + | }}{{#ifexpr: {{#var:date2_d}} < {{#var:date1_d}} |
+ | | {{#vardefine:age|{{#expr:{{#var:date2_y}}-{{#var:date1_y}}-1}}}} | ||
+ | }}{{#ifexpr: {{#var:date2_d}} = {{#var:date1_d}} | ||
+ | | {{#vardefine:age|{{#expr:{{#var:date2_y}}-{{#var:date1_y}}}}}} | ||
}} | }} | ||
− | }}</includeonly><noinclude> | + | }}{{#ifeq: {{#var:date1_m}} | 00 |
+ | | {{#vardefine:age|{{#expr:{{#var:date2_y}}-{{#var:date1_y}}-1}}-{{#expr:{{#var:date2_y}}-{{#var:date1_y}}}}}} | ||
+ | }}{{#var:age}}</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). | ||
Revision as of 17:28, 26 August 2016
Convert a date in the format YYYY-MM-DD to an age in years (based on the current date).
Usage
{{age|1991-06-23}}
returns
33
Optional parameter
Add a second date to calculate the age on that date.
{{age|1991-06-23|1999-09-09}}
returns
8