Template:Age in years, months and days/display

0天

文档图示 模板文档[查看] [编辑] [历史] [清除缓存]

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 and use varies, this template does not automatically place a comma after the months. If a serial comma is desired, adding |sc=y to the template invocation will include one.

See Wikipedia:Age calculation templates for more information on using this kind of template.

Syntax

编辑
{{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 "23年10个月又9天"
{{Age in years, months and days|2001|01|15|2008|09|05}} returns "7年7个月又21天"
{{Age in years, months and days|2016|8|4|2016|9|5}} returns "1个月1天"

This template can handle an ambiguous start date:

{{Age in years, months and days|year=2010|month=9}} returns "错误:需要有效的年月日"
{{Age in years, months and days|2009|6||2011|2|21}} returns "错误:需要有效的年月日"

But it cannot handle an ambiguous end date:

{{Age in years, months and days|2012|11|2|2016|4}} returns "错误:第二个日期应该是年月日"
{{Age in years, months and days|2012|11|2|2017}} returns "错误:第二个日期应该是年月日"

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年2个月又30天"
{{Age in years, months and days|2007|3|12|2015|7|11}} returns "8年3个月又29天"

To add a serial comma specify |sc=y.

{{Age in years, months and days|year=2001|month=1|day=15|sc=y}} returns "23年,10个月又9天"
{{Age in years, months and days|2001|1|15|2008|9|5|sc=y}} returns "7年,7个月又21天"
{{Age in years, months and days|表达式错误:预期外的<运算符。|表达式错误:预期外的<运算符。|表达式错误:预期外的<运算符。|sc=y}} returns "错误:需要有效的年月日"

TemplateData

编辑
这是用于新版可视化编辑器及其他工具的模板数据文档。

Age in years, months and days模板数据

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.

模板参数[编辑模板数据]

参数描述类型状态
Year ('from' date)1 year

The year of the (first) date

数字必需
Month ('from' date)2 month

Number of the month of the (first) date

数字必需
Day of month ('from' date)3 day

The day of the month of the (first) date

数字可选
Year ('to' date)4

The year of the 'to' date, if required

默认值
the current year
数字可选
Month ('to' date)5

Number of the month of the 'to' date, if required

默认值
the current month
数字可选
Day of month ('to' date)6

The day of the month of the 'to' date, if required

默认值
the current day
数字可选
Serial commasc

Enter 'y' to turn on the serial comma after the months

默认值
none
单行文本可选

See also

编辑


Template:Birth, death and age templates