Template:Time difference
| This template uses Lua: |
This template calculates the date/time difference between two dates/times. 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
{{time difference|date1|date2|options}}
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 difference from date1 to date2 (date2 − date1).
Dates are 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:
{{time difference|1 Jan 2001|March 4, 2002}}→ 1 year, 2 months and 3 days{{time difference|1 Jan 2001|March 4, 2002|abbr=on}}→ 1y 2m 3d{{time difference|B.C.E. 1 Feb 120|28 FEB 1900}}→ 2019 years and 27 days
Parameters
| Parameter | Description |
|---|---|
abbr=off | Unit names in full (default): year, month, day, hour, minute. |
abbr=on | Units shown as a single letter with no space between number and unit: y, m, d, h, m. |
disp=age | If no show 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 sep=space by default. This is compatible with {{age for infant}}. |
disp=raw | Display numbers only with sep=space. |
duration=on | Period is a duration (has an extra day to include the end date). |
format=commas | Numbers over 999 are formatted with commas. |
format=raw | 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. |
sep=comma | Separator between items is a comma: 1 year, 2 months, 3 days. The default is 1 year, 2 months and 3 days. |
sep=, | Same as sep=comma. |
sep=serialcomma | Use a serial comma: 1 year, 2 months, and 3 days. |
sep=space | Use a space: 1 year 2 months 3 days. |
sc=y | Change the default separator to use a serial comma. Also accepts sc=yes and sc=on. |
show=y | years |
show=ym | years and months |
show=ymd | years, months and days (default) |
show=ymw | years, months and weeks |
show=ymwd | years, months, weeks and days |
show=yd | years and days |
show=m | months |
show=md | months and days |
show=w | weeks |
show=wd | weeks and days |
show=d | days |
show=dh | days and hours |
show=dhm | days, hours and minutes |
show=dhms | days, hours, minutes and seconds |
show=ymdh | ymd + hours |
show=ymdhm | ymd + hours and minutes |
show=ymwdh | ymwd + hours |
show=ymwdhm | ymwd + hours and minutes |
show=h | hours (result would be 48 hours for a difference of 2 days) |
show=hm | hours and minutes |
show=hms | hours, minutes and seconds |
show=M | minutes (uppercase M because m is months) |
show=s | seconds |
round=on | Round the least-significant unit specified with the show= parameter. |
round=months | Round to nearest month using show=ym. |
round=weeks | Round to nearest week using show=ymw. |
round=days | Round to nearest day using show=ymd. |
round=hours | Round to nearest hour using show=ymdh. |
sortable=on | 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). |
sortable=off | No sort key (default). |
sortable=debug | Output a visible sort key for testing. |
TemplateData
TemplateData for Time difference
Calculates the date/time difference between two dates
| Parameter | Description | Type | Status | |
|---|---|---|---|---|
| Start date | 1 | The first day of the period for which duration will be calculated
| Date | required |
| End date | 2 | The last day of the period for which duration will be calculated
| Date | required |
| Abbreviation | abbr | Show unit names as full (year, month, day, hour, minute) or single characters (y, m, d, h, m)
| String | optional |
| Display options | disp | With "age" 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. With "raw" to show numbers only
| String | optional |
| Duration | duration | Period is a duration (has an extra day to include the end date)
| String | optional |
| Format | format | With "commas", numbers over 999 are formatted with commas. With "raw", 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.
| String | optional |
| Separator | sep | Separator between items. With "comma": 1 year, 2 months, 3 days. The default is 1 year, 2 months and 3 days.
| String | optional |
| Show units | show | Which units to display. y=years, m=months, w=weeks, d=days, h=hours, M=minutes, s=seconds
| String | optional |
| Rounding | round | with "on": round the least-significant unit specified with the show parameter.; with "months", "weeks", "days", "hours" round to that time period
| String | optional |
| Sortable | sortable | Output a hidden sort key for sortable tables based on the number of days in the date difference (includes a fraction of a day to handle time differences).
| String | optional |