• Home
  • Random
  • Nearby
  • Log in
  • Settings
Donate Now If Wikipedia is useful to you, please give today.
  • About Wikipedia
  • Disclaimers
Beta Wikipedia

Template:Dts

  • Template
  • Discussion
  • Language
  • Watch
  • Edit
Template documentation[view] [edit] [history] [purge]

Dts stands for Date Table Sorting and is used to correctly sort and display dates in a sortable table (see Help:Sorting).

Contents

  • 1 What it solves
  • 2 Parameters
    • 2.1 Input
    • 2.2 Output
    • 2.3 Linking
  • 3 Examples
  • 4 Limitation
  • 5 Error handling
  • 6 See also

What it solves

edit

Normally, for proper sorting, dates must be entered in YYYY-MM-DD format. However, that format does not conform to the Manual of Style for date display. This template automatically creates the hidden <span style="display:none">1776-07-04</span> for sorting purposes and then displays the date like this: July 4, 1776. To hide the output, use the {{dtsh}} template instead.

Parameters

edit
Date display can be modified using two named parameters.
  • To use international date formats, use the format=dmy parameter.
  • To turn off the suppression of word wraps, use the nowrap=off parameter.
The year, month and day can either be entered separately or as a single date.
{{dts|year|month|day|BC}} {{dts|date}}
  • 1st parameter – Year (optional if month is given)
    • Year number – number in the range -9999 through 9999: the numbers -9999 through 0 are used without "bc" and represent astronomical years -9999 through 0, the numbers 1 through 9999 represent that year AD, or BC with the fourth parameter set to bc or BC
  • 2nd parameter – Month (optional if the day is not given either)
    • Full month name – February or february
    • Abbreviated month name – Feb or feb
    • Month number – 2 or 02
  • 3rd parameter – Day (optional)
    • Day number – 7 or 07
  • 4th parameter – optional with value BC or bc
    • Used with a positive year number

Thus e.g. for the year 5 BC we can use "5|bc" or "-4".

A time period (year or month and year) is sorted according to its start, and time periods with the same starting moment are in order of descending length: a year comes before its first month; a month comes before its first day.

  • 1st parameter – the full date in international, US or YYYY-MM-DD format
    • It uses {{#time:}} and so is limited to what the parser function can handle (e.g. it won't go beyond 100 AD).
    • International format is left as it is. YYYY-MM-DD format defaults to US format.
    • Abbreviated months are accepted.
    • Capitalisation and comma mistakes are corrected.

Input

edit

{{dts|year|month|day|BC}}

  • {{dts|1776|July|4}}

{{dts|date}}

  • {{dts|1776-07-04}}
  • {{dts|July 4, 1776}}
  • {{dts|4 July 1776}}

When supplying a single parameter for the date, it is accepted and interpreted according to the php date/time format, except that a single number is interpreted as a year. By default the date is shown as supplied. If the first parameter is not just the year, but no format parameter is supplied, due to a call of function #time the maximum number of calls of this template on a page is 1200.

Using format=mdy, format=dmy, or format=auto produces a format that depends on, but is not necessarily equal to the format of the supplied date. This requires multiple calls of function #time, reducing the maximum number of calls of this template on a page in the worst case to 88, see below.

Also see the examples below.

Output

edit

Output sent to table

  • <span style="display:none">01776-07-04</span> July 4, 1776 or
  • <span style="display:none">01776-07-04</span> 4 July 1776

Output displayed to user

  • July 4, 1776 or
  • 4 July 1776

Linking

edit

The template formerly linked dates automatically. To turn linking off the parameter link=off was used. In accordance with current guidelines linking is no longer supported. Please do not use this parameter. Please remove it from existing transclusions.

Examples

edit
Normal function of the template. The template with debug=yes, which causes hidden parts to appear:
Template syntax Date rendered
{{dts|2001}} 000000002001-01-01-00002001
{{dts||1|1}} 000000002025-01-01-0000January 1
{{dts|-50|July}} -999999999950-07-01-0000July 50 BC
{{dts|-1000|July|4}} -999999999000-07-04-0000July 4, 1000 BC
{{dts|5|July|4|BC}} -999999999995-07-04-0000July 4, 5 BC
{{dts|40|July|4|BC}} -999999999960-07-04-0000July 4, 40 BC
{{dts|1|July|4|BC}} -999999999999-07-04-0000July 4, 1 BC
{{dts|88|July|4}} 000000000088-07-04-0000July 4, 88
{{dts|2007|7|11}} 000000002007-07-11-0000July 11, 2007
{{dts|2001|sep|11}} 000000002001-09-11-0000Sep 11, 2001
{{dts|format=dmy|2001}} 000000002001-01-01-00002001
{{dts|format=dmy||1|1}} 000000002025-01-01-00001 January
{{dts|format=dmy|-50|July}} -999999999950-07-01-0000July 50 BC
{{dts|format=dmy|-1000|July|4}} -999999999000-07-04-00004 July 1000 BC
{{dts|format=dmy|5|July|4|BC}} -999999999995-07-04-00004 July 5 BC
{{dts|format=dmy|40|July|4|BC}} -999999999960-07-04-00004 July 40 BC
{{dts|format=dmy|1|July|4|BC}} -999999999999-07-04-00004 July 1 BC
{{dts|format=dmy|88|July|4}} 000000000088-07-04-00004 July 88
{{dts|format=dmy|2007|7|11}} 000000002007-07-11-000011 July 2007
{{dts|format=dmy|2001|sep|11}} 000000002001-09-11-000011 Sep 2001
{{dts|2001}} 000000002001-01-01-00002001
{{dts|1 January}} 000000002025-01-01-00001 January
{{dts|July 19}} 000000002025-07-19-0000July 19
{{dts|10 July 1994}} 000000001994-07-10-000010 July 1994
{{dts|July 4, 1555}} 000000001555-07-04-0000July 4, 1555
{{dts|24 Sep 2004}} 000000002004-09-24-000024 Sep 2004
{{dts|format=mdy|1 July 1893}} 000000001893-07-01-0000July 1, 1893
{{dts|format=dmy|July 4, 1688}} 000000001688-07-04-00004 July 1688
{{dts|format=dmy|2007-7-11}} 000000002007-07-11-000011 July 2007
{{dts|format=auto|4 July, 1688}} Error in Template:Dts: 'auto' is not a valid format
{{dts|format=auto|July 4 1688}} Error in Template:Dts: 'auto' is not a valid format
{{dts|2001-11-11}} 000000002001-11-11-0000November 11, 2001
Template syntax Date rendered
{{dts|debug=yes|2001}} 000000002001-01-01-00002001
{{dts|debug=yes||1|1}} 000000002025-01-01-0000January 1
{{dts|debug=yes|-50|July}} -999999999950-07-01-0000July 50 BC
{{dts|debug=yes|-1000|July|4}} -999999999000-07-04-0000July 4, 1000 BC
{{dts|debug=yes|5|July|4|BC}} -999999999995-07-04-0000July 4, 5 BC
{{dts|debug=yes|40|July|4|BC}} -999999999960-07-04-0000July 4, 40 BC
{{dts|debug=yes|1|July|4|BC}} -999999999999-07-04-0000July 4, 1 BC
{{dts|debug=yes|88|July|4}} 000000000088-07-04-0000July 4, 88
{{dts|debug=yes|2007|7|11}} 000000002007-07-11-0000July 11, 2007
{{dts|debug=yes|2001|sep|11}} 000000002001-09-11-0000Sep 11, 2001
{{dts|format=dmy|debug=yes|2001}} 000000002001-01-01-00002001
{{dts|format=dmy|debug=yes||1|1}} 000000002025-01-01-00001 January
{{dts|format=dmy|debug=yes|-50|July}} -999999999950-07-01-0000July 50 BC
{{dts|format=dmy|debug=yes|-1000|July|4}} -999999999000-07-04-00004 July 1000 BC
{{dts|format=dmy|debug=yes|5|July|4|BC}} -999999999995-07-04-00004 July 5 BC
{{dts|format=dmy|debug=yes|40|July|4|BC}} -999999999960-07-04-00004 July 40 BC
{{dts|format=dmy|debug=yes|1|July|4|BC}} -999999999999-07-04-00004 July 1 BC
{{dts|format=dmy|debug=yes|88|July|4}} 000000000088-07-04-00004 July 88
{{dts|format=dmy|debug=yes|2007|7|11}} 000000002007-07-11-000011 July 2007
{{dts|format=dmy|debug=yes|2001|sep|11}} 000000002001-09-11-000011 Sep 2001
{{dts|debug=yes|2001}} 000000002001-01-01-00002001
{{dts|debug=yes|1 January}} 000000002025-01-01-00001 January
{{dts|debug=yes|July 19}} 000000002025-07-19-0000July 19
{{dts|debug=yes|10 July 1994}} 000000001994-07-10-000010 July 1994
{{dts|debug=yes|July 4, 1555}} 000000001555-07-04-0000July 4, 1555
{{dts|debug=yes|24 Sep 2004}} 000000002004-09-24-000024 Sep 2004
{{dts|format=mdy|debug=yes|1 July 1893}} 000000001893-07-01-0000July 1, 1893
{{dts|format=dmy|debug=yes|July 4, 1688}} 000000001688-07-04-00004 July 1688
{{dts|format=dmy|debug=yes|2007-7-11}} 000000002007-07-11-000011 July 2007
{{dts|format=auto|debug=yes|4 July, 1688}} Error in Template:Dts: 'auto' is not a valid format
{{dts|format=auto|debug=yes|July 4 1688}} Error in Template:Dts: 'auto' is not a valid format
{{dts|debug=yes|2001-11-11}} 000000002001-11-11-0000November 11, 2001

Limitation

edit

Template:Dts/formauto calls #time with format strings with a total length of up to 68 characters. The worst case is when the default case of the #switch applies, e.g. for the format 1876-08-25. In that case the template can only be called 88 times (here less because of the other examples):

August 25, 1801; August 25, 1802; August 25, 1803; August 25, 1804; August 25, 1805; August 25, 1806; August 25, 1807; August 25, 1808; August 25, 1809; August 25, 1810; August 25, 1811; August 25, 1812; August 25, 1813; August 25, 1814; August 25, 1815; August 25, 1816; August 25, 1817; August 25, 1818; August 25, 1819; August 25, 1820; August 25, 1821; August 25, 1822; August 25, 1823; August 25, 1824; August 25, 1825; August 25, 1826; August 25, 1827; August 25, 1828; August 25, 1829; August 25, 1830; August 25, 1831; August 25, 1832; August 25, 1833; August 25, 1834; August 25, 1835; August 25, 1836; August 25, 1837; August 25, 1838; August 25, 1839; August 25, 1840; August 25, 1841; August 25, 1842; August 25, 1843; August 25, 1844; August 25, 1845; August 25, 1846; August 25, 1847; August 25, 1848; August 25, 1849; August 25, 1850; August 25, 1851; August 25, 1852; August 25, 1853; August 25, 1854; August 25, 1855; August 25, 1856; August 25, 1857; August 25, 1858; August 25, 1859; August 25, 1860; August 25, 1861; August 25, 1862; August 25, 1863; August 25, 1864; August 25, 1865; August 25, 1866; August 25, 1867; August 25, 1868; August 25, 1869; August 25, 1870; August 25, 1871; August 25, 1872; August 25, 1873; August 25, 1874; August 25, 1875; August 25, 1876; August 25, 1877; August 25, 1878; August 25, 1879; August 25, 1880; August 25, 1881; August 25, 1882; August 25, 1883; August 25, 1884; August 25, 1885; August 25, 1886; August 25, 1887; August 25, 1888; Error: Too many #time calls.

Error handling

edit

During early 2009, Template:Dts generated month names for invalid month numbers, such as number 23 displaying "November". No warning is displayed, for the formatted page, that such invalid dates are being used on the page.

See also

edit
  • {{dtsh}}, hides the template's output
  • {{TBA}}, allows quarters, and allows sorting of time periods by end date.
  • m:Template:dts (backlinks, edit), since on Meta e.g. 09999 9999 induces numeric sort mode, "&" is prefixed to force string sort mode.
  • {{dts1}}
  • {{dts vgr}}, for video game release dates.
  • {{sort}}, sorting by a specified key
  • {{sortname}}, full name sorting.
  • {{tts}}, for sorting times in result tables of athletic events (only needed in certain cases - see template documentation)

da:Skabelon:Dts id:Templat:Dts it:Template:Dts

no:Mal:Sorterbar dato pt:Predefinição:Dts th:แม่แบบ:Dts

The above documentation is transcluded from Template:Dts/doc. (edit | history)
Editors can experiment in this template's sandbox (create | mirror) and testcases (create) pages.
Add categories to the /doc subpage. Subpages of this template.
Retrieved from "https://en.wikipedia.beta.wmcloud.org/w/index.php?title=Template:Dts&oldid=654026"
Last edited on 6 June 2025, at 15:05

Languages

    • العربية
    • Čeština
    • Deutsch
    • فارسی
    • Polski
    • Русский
    • Українська
    • 中文
    Beta Wikipedia
    • Wikimedia Foundation
    • Powered by MediaWiki
    • This page was last edited 15:05, 6 June 2025 by Beta Wikipedia user Dom walden. Based on work by Beta Wikipedia users JustBerry, Jdlrobson and Anomie and Beta Wikipedia anonymous users imported>Mr. Stradivarius, imported>Jimp, imported>AnomieBOT, imported>HJ Mitchell, imported>Plastikspork, imported>Chamal N, imported>Joyous!, 76.178.124.146, imported>MPJ-DK, imported>Batshaft, imported>GregorB, imported>Little Mountain 5, 72.193.193.58, imported>Gary King, imported>-Majestic-, imported>Hemmingsen, imported>Framhein, imported>Andrwsc, imported>16@r, imported>Patrick, imported>Van helsing, imported>Trialsanderrors and imported>MrDolomite.
    • Content is available under CC BY-SA 4.0 unless otherwise noted.
    • Privacy policy
    • About Wikipedia
    • Disclaimers
    • Contact Wikipedia
    • Code of Conduct
    • Developers
    • Statistics
    • Cookie statement
    • Terms of use
    • Desktop