Open main menu

Changes

m
add {{documentation subpage}}
{{documentation subpage}}
{{Lua|Module:Age|Module:Date}}
This template calculates the date/time difference between two dates. Dates in the [[Gregorian calendar]] from 9999 BCE to 9999 CE are supported. The calendar is proleptic—it is assumed to apply at all times with no irregularities.

== Syntax ==
{{Template shortcuts|t-int}}
*<code>&#123;{time interval|''date1''|''date2''|''options''}}</code>

There are two positional arguments: ''date1'' and ''date2''. The default for each is the current date and time.

The result displays text representing the time interval from ''date1'' to ''date2'' (''date2'' − ''date1'').

Dates are [[Coordinated Universal Time|UTC]]—local times and time zones are not supported.

Dates are checked for validity. For example, 29 February 2000 is accepted, but 29 February 1900 is not a valid date.

Each date can include an era or a time, and a variety of formats are accepted. Examples of valid dates are:
:1900-02-01
:1900-2-1
:1900-02-01 14:45
:1 FEB 1900
:February 1, 1900
:February 1 1900 14:45
:2:45 pm February 1 1900
:1 February 1900 2:45 p.m.
:BC 1 Feb 120

Examples:
*<code><nowiki>{{time interval|1 Jan 2001|March 4, 2002}}</nowiki></code> → {{time interval|1 Jan 2001|March 4, 2002}}
*<code><nowiki>{{time interval|1 Jan 2001|March 4, 2002|abbr=on}}</nowiki></code> → {{time interval|1 Jan 2001|March 4, 2002|abbr=on}}
*<code><nowiki>{{time interval|B.C.E. 1 Feb 120|28 FEB 1900}}</nowiki></code> → {{time interval|B.C.E. 1 Feb 120|28 FEB 1900}}

== Parameters ==
{| class="wikitable"
! Parameter !! Description
|-
| <code>abbr=off</code> || Unit names in full (default): year, month, day, hour, minute.
|-
| <code>abbr=on</code> || Units shown as a single letter with no space between number and unit: y, m, d, h, m.
|-
| <code>disp=age</code> || If no <code>show</code> has been entered, years are displayed if the age is above 3 years, years and months from 1 to 3 years, or months and days for under 1 year. Sets <code>sep=space</code> by default. This is compatible with {{tl|age for infant}}.
|-
| <code>disp=raw</code> || Display numbers only with <code>sep=space</code>.
|-
| <code>duration=on</code> || Period is a duration (has an extra day to include the end date).
|-
| <code>format=commas</code> || Numbers over 999 are formatted with commas.
|-
| <code>format=raw</code> || Use a hyphen (-) to indicate a negative date difference instead of a minus (−); a hyphen may allow the result to be used in a calculation.
|-
| <code>sep=comma</code> || Separator between items is a comma: 1 year, 2 months, 3 days. The default is 1 year, 2 months and 3 days.
|-
| <code>sep=,</code> || Same as <code>sep=comma</code>.
|-
| <code>sep=serialcomma</code> || Use a [[serial comma]]: 1 year, 2 months, and 3 days.
|-
| <code>sep=space</code> || Use a space: 1 year 2 months 3 days.
|-
| <code>sc=y</code> || Change the default separator to use a serial comma. Also accepts <code>sc=yes</code> and <code>sc=on</code>.
|-
| <code>show=y</code> || years
|-
| <code>show=ym</code> || years and months
|-
| <code>show=ymd</code> || years, months and days (default)
|-
| <code>show=ymw</code> || years, months and weeks
|-
| <code>show=ymwd</code> || years, months, weeks and days
|-
| <code>show=yd</code> || years and days
|-
| <code>show=m</code> || months
|-
| <code>show=md</code> || months and days
|-
| <code>show=w</code> || weeks
|-
| <code>show=wd</code> || weeks and days
|-
| <code>show=d</code> || days
|-
| <code>show=dh</code> || days and hours
|-
| <code>show=dhm</code> || days, hours and minutes
|-
| <code>show=dhms</code> || days, hours, minutes and seconds
|-
| <code>show=ymdh</code> || ymd + hours
|-
| <code>show=ymdhm</code> || ymd + hours and minutes
|-
| <code>show=ymwdh</code> || ymwd + hours
|-
| <code>show=ymwdhm</code> || ymwd + hours and minutes
|-
| <code>show=h</code> || hours (result would be 48 hours for a difference of 2 days)
|-
| <code>show=hm</code> || hours and minutes
|-
| <code>show=hms</code> || hours, minutes and seconds
|-
| <code>round=on</code> || Round the least-significant unit specified with the <code>show=</code> parameter.
|-
| <code>round=months</code> || Round to nearest month using <code>show=ym</code>.
|-
| <code>round=weeks</code> || Round to nearest week using <code>show=ymw</code>.
|-
| <code>round=days</code> || Round to nearest day using <code>show=ymd</code>.
|-
| <code>round=hours</code> || Round to nearest hour using <code>show=ymdh</code>.
|-
| <code>sortable=on</code> || Output a hidden sort key based on the number of days in the date difference (includes a fraction of a day to handle time differences).
|-
| <code>sortable=off</code> || No sort key (default).
|-
| <code>sortable=debug</code> || Output a visible sort key for testing.
|}
Anonymous user