Template:Dts

From Viewpoints Intelligent Archive
Jump to: navigation, search
Template documentation[view] [edit] [history] [purge]

{{#ifeq:dts |doc

    | 

{{#ifeq:show |show

|
        }}{{#if: |
         |   {{#ifexist:Template:Dts
                  | [[Category:{{#switch:Template |Template=Template |Module=Module |User=User |#default=Wikipedia}} documentation pages]]
                  |
                 }}
        }}
    | 
   }}

Dts (date time sorting) is used to correctly sort and display dates in a sortable table (see Help:Sorting).

What it solves

Dates in their customary formats, if simply treated as alphanumeric text strings, sort in nonsensical ways:

  • 1/8/2013 sorts alphanumerically before 5/3/1967, because 1 is less than 5;
  • February 5, 1922 sorts alphanumerically before January 3, 1922, because F comes before J.

Use of the YYYY-MM-DD format would solve this problem, but with minor exceptions that format is not used in articles (see WP:DATEFORMAT).

This template automatically attaches a "hidden key" to dates, causing them to sort correctly while still being displayed in one of the customary display formats such as February 5, 1922 or 5 Feb 1922.

Parameters

Dates

The year, month and day can either be entered separately or as a single date.
{{{{#if:dts|dts| tlf|...}}{{#ifeq:year|year| |year | }}{{#ifeq:month|month| |month | }}{{#ifeq:day|day| |day | }}{{#ifeq:BC|BC| |BC | }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}}} {{{{#if:dts|dts| tlf|...}}{{#ifeq:date|date| |date | }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}}}
  • 1st parameter – Year (optional if month is given)
    • Positive number (1 to 999,999,999,999) represent years AD or BC (dependant on the fourth parameter).
    • Negative numbers (−1 to −999,999,999,999) represent years BC (without the fourth parameter).
    • Year numbers must not contain commas or other formatting.
  • 2nd parameter – Month (optional if the day is not given either)
    • Full month name – e.g. February
    • Abbreviated month name – e.g. Feb
    • Month number – (either zero-padded or not) e.g. 2 or 02
  • 3rd parameter – Day (optional)
    • Day number – (either zero-padded or not) e.g. 7 or 07
  • 4th parameter – (optional)
    • May be BC, AD, BCE or CE
    • Used with a positive year number
  • 1st parameter – the full date
    • By default YYYY-MM-DD format becomes month-day-year format while other formats remain in the order they are input.
    • Abbreviated months are accepted and are abbreviated in the output.
    • Capitalisation and comma mistakes are corrected.
    • A single number is interpreted as a year, otherwise the date is parsed by the module. The following formats are accepted:
      • YYYY-MM-DD
      • DD-MM-YYYY
      • DD Month YYYY
      • Month DD, YYYY
      • YYYY-MM
      • DD Month
      • Month DD
      • Month YYYY
      • YYYY
      • Month
    • Day and month numbers may be 1 or 2 digits, and year numbers may only be 3 or 4 digits. If you need to input a number less than 1000, use leading zeroes (e.g. "0700").
    • BC years can only be parsed if the date is only the year number.
    • If you need to include the day or month for BC years or years greater than 9999, you must use separate parameters for year, month and day.


{{#if:{{{{#if:dts|dts| tlf|...}}{{#ifeq:year|year| |year | }}{{#ifeq:x|| |{{{3}}} | }}{{#ifeq:x|| |{{{4}}} | }}{{#ifeq:x|| |{{{5}}} | }}{{#ifeq:x|| |{{{6}}} | }}{{#ifeq:x|| |{{{7}}} | }}{{#ifeq:x|| |{{{8}}} | }}{{#ifeq:x|| |{{{9}}} | }}}}| {{#if:| {{#if:| {{#if:{{{{#if:dts|dts| tlf|...}}{{#ifeq:month|month| |month | }}{{#ifeq:x|| |{{{3}}} | }}{{#ifeq:x|| |{{{4}}} | }}{{#ifeq:x|| |{{{5}}} | }}{{#ifeq:x|| |{{{6}}} | }}{{#ifeq:x|| |{{{7}}} | }}{{#ifeq:x|| |{{{8}}} | }}{{#ifeq:x|| |{{{9}}} | }}}}| {{#if:{{{{#if:dts|dts| tlf|...}}{{#ifeq:month year|month year| |month year | }}{{#ifeq:x|| |{{{3}}} | }}{{#ifeq:x|| |{{{4}}} | }}{{#ifeq:x|| |{{{5}}} | }}{{#ifeq:x|| |{{{6}}} | }}{{#ifeq:x|| |{{{7}}} | }}{{#ifeq:x|| |{{{8}}} | }}{{#ifeq:x|| |{{{9}}} | }}}}| {{#if:{{{{#if:dts|dts| tlf|...}}{{#ifeq:day month year|day month year| |day month year | }}{{#ifeq:x|| |{{{3}}} | }}{{#ifeq:x|| |{{{4}}} | }}{{#ifeq:x|| |{{{5}}} | }}{{#ifeq:x|| |{{{6}}} | }}{{#ifeq:x|| |{{{7}}} | }}{{#ifeq:x|| |{{{8}}} | }}{{#ifeq:x|| |{{{9}}} | }}}}| {{#if:{{{{#if:dts|dts| tlf|...}}{{#ifeq:month day, year|month day, year| |month day, year | }}{{#ifeq:x|| |{{{3}}} | }}{{#ifeq:x|| |{{{4}}} | }}{{#ifeq:x|| |{{{5}}} | }}{{#ifeq:x|| |{{{6}}} | }}{{#ifeq:x|| |{{{7}}} | }}{{#ifeq:x|| |{{{8}}} | }}{{#ifeq:x|| |{{{9}}} | }}}}| {{#if:{{{{#if:dts|dts| tlf|...}}{{#ifeq:day month|day month| |day month | }}{{#ifeq:x|| |{{{3}}} | }}{{#ifeq:x|| |{{{4}}} | }}{{#ifeq:x|| |{{{5}}} | }}{{#ifeq:x|| |{{{6}}} | }}{{#ifeq:x|| |{{{7}}} | }}{{#ifeq:x|| |{{{8}}} | }}{{#ifeq:x|| |{{{9}}} | }}}}| {{#if:{{{{#if:dts|dts| tlf|...}}{{#ifeq:month day|month day| |month day | }}{{#ifeq:x|| |{{{3}}} | }}{{#ifeq:x|| |{{{4}}} | }}{{#ifeq:x|| |{{{5}}} | }}{{#ifeq:x|| |{{{6}}} | }}{{#ifeq:x|| |{{{7}}} | }}{{#ifeq:x|| |{{{8}}} | }}{{#ifeq:x|| |{{{9}}} | }}}}| {{#if:{{{{#if:dts|dts| tlf|...}}{{#ifeq:YYYY-MM-DD|YYYY-MM-DD| |YYYY-MM-DD | }}{{#ifeq:x|| |{{{3}}} | }}{{#ifeq:x|| |{{{4}}} | }}{{#ifeq:x|| |{{{5}}} | }}{{#ifeq:x|| |{{{6}}} | }}{{#ifeq:x|| |{{{7}}} | }}{{#ifeq:x|| |{{{8}}} | }}{{#ifeq:x|| |{{{9}}} | }}}}| {{#if:{{{{#if:dts|dts| tlf|...}}{{#ifeq:year|year| |year | }}{{#ifeq:month|month| |month | }}{{#ifeq:x|| |{{{4}}} | }}{{#ifeq:x|| |{{{5}}} | }}{{#ifeq:x|| |{{{6}}} | }}{{#ifeq:x|| |{{{7}}} | }}{{#ifeq:x|| |{{{8}}} | }}{{#ifeq:x|| |{{{9}}} | }}}}| {{#if:| {{#if:| {{#if:{{{{#if:dts|dts| tlf|...}}{{#ifeq:year|year| |year | }}{{#ifeq:month|month| |month | }}{{#ifeq:day|day| |day | }}{{#ifeq:x|| |{{{5}}} | }}{{#ifeq:x|| |{{{6}}} | }}{{#ifeq:x|| |{{{7}}} | }}{{#ifeq:x|| |{{{8}}} | }}{{#ifeq:x|| |{{{9}}} | }}}}| {{#if:| {{#if:{{{{#if:dts|dts| tlf|...}}{{#ifeq:year|year| |year | }}{{#ifeq:month|month| |month | }}{{#ifeq:day|day| |day | }}{{#ifeq:era|era| |era | }}{{#ifeq:x|| |{{{6}}} | }}{{#ifeq:x|| |{{{7}}} | }}{{#ifeq:x|| |{{{8}}} | }}{{#ifeq:x|| |{{{9}}} | }}}}| {{#if:| {{#if:{{{{#if:dts|dts| tlf|...}}{{#ifeq:|| | | }}{{#ifeq:month|month| |month | }}{{#ifeq:x|| |{{{4}}} | }}{{#ifeq:x|| |{{{5}}} | }}{{#ifeq:x|| |{{{6}}} | }}{{#ifeq:x|| |{{{7}}} | }}{{#ifeq:x|| |{{{8}}} | }}{{#ifeq:x|| |{{{9}}} | }}}}| {{#if:{{{{#if:dts|dts| tlf|...}}{{#ifeq:|| | | }}{{#ifeq:month|month| |month | }}{{#ifeq:day|day| |day | }}{{#ifeq:x|| |{{{5}}} | }}{{#ifeq:x|| |{{{6}}} | }}{{#ifeq:x|| |{{{7}}} | }}{{#ifeq:x|| |{{{8}}} | }}{{#ifeq:x|| |{{{9}}} | }}}}|
Examples
input style input code hidden sort key visible output
{{{{#if:dts|dts| tlf|...}}{{#ifeq:year|year| |year | }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}}}|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:

|1893|||{{{4}}} {{#if: |1893||{{{3}}} {{#if: |1893|{{{2}}} {{#if:1893 |1893
         }}
      }}
   }}
}}{{#if:
|format=
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour 1893
}}
{{{a}}}|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:

|-89|||{{{4}}} {{#if: |-89||{{{3}}} {{#if: |-89|{{{2}}} {{#if:-89 |-89
         }}
      }}
   }}
}}{{#if:
|format=
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour 89 BC
}}
{{{a}}}|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:

|-10000|||{{{4}}} {{#if: |-10000||{{{3}}} {{#if: |-10000|{{{2}}} {{#if:-10000 |-10000
         }}
      }}
   }}
}}{{#if:
|format=
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour 10,000 BC
}}
{{{{#if:dts|dts| tlf|...}}{{#ifeq:month|month| |month | }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}}}|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:

|Oct|||{{{4}}} {{#if: |Oct||{{{3}}} {{#if: |Oct|{{{2}}} {{#if:Oct |Oct
         }}
      }}
   }}
}}{{#if:
|format=
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour Oct
}}
{{{{#if:dts|dts| tlf|...}}{{#ifeq:month year|month year| |month year | }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}}}|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:

|February 1767|||{{{4}}} {{#if: |February 1767||{{{3}}} {{#if: |February 1767|{{{2}}} {{#if:February 1767 |February 1767
         }}
      }}
   }}
}}{{#if:
|format=
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour February 1767
}}
{{{{#if:dts|dts| tlf|...}}{{#ifeq:day month year|day month year| |day month year | }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}}}|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:

|12 Aug 1987|||{{{4}}} {{#if: |12 Aug 1987||{{{3}}} {{#if: |12 Aug 1987|{{{2}}} {{#if:12 Aug 1987 |12 Aug 1987
         }}
      }}
   }}
}}{{#if:
|format=
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour 12 Aug 1987
}}
{{{{#if:dts|dts| tlf|...}}{{#ifeq:month day, year|month day, year| |month day, year | }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}}}|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:

|July 1, 1867|||{{{4}}} {{#if: |July 1, 1867||{{{3}}} {{#if: |July 1, 1867|{{{2}}} {{#if:July 1, 1867 |July 1, 1867
         }}
      }}
   }}
}}{{#if:
|format=
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour July 1, 1867
}}
{{{{#if:dts|dts| tlf|...}}{{#ifeq:day month|day month| |day month | }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}}}|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:

|25 October|||{{{4}}} {{#if: |25 October||{{{3}}} {{#if: |25 October|{{{2}}} {{#if:25 October |25 October
         }}
      }}
   }}
}}{{#if:
|format=
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour 25 October
}}
{{{{#if:dts|dts| tlf|...}}{{#ifeq:month day|month day| |month day | }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}}}|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:

|Jan 1|||{{{4}}} {{#if: |Jan 1||{{{3}}} {{#if: |Jan 1|{{{2}}} {{#if:Jan 1 |Jan 1
         }}
      }}
   }}
}}{{#if:
|format=
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour Jan 1
}}
{{{{#if:dts|dts| tlf|...}}{{#ifeq:YYYY-MM-DD|YYYY-MM-DD| |YYYY-MM-DD | }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}}}|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:

|2014-12-09|||{{{4}}} {{#if: |2014-12-09||{{{3}}} {{#if: |2014-12-09|{{{2}}} {{#if:2014-12-09 |2014-12-09
         }}
      }}
   }}
}}{{#if:
|format=
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour December 9, 2014
}}
{{{{#if:dts|dts| tlf|...}}{{#ifeq:year|year| |year | }}{{#ifeq:month|month| |month | }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}}}|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:

|1990|10||{{{4}}} {{#if: |1990|10|{{{3}}} {{#if:10 |1990|10 {{#if:1990 |1990
         }}
      }}
   }}
}}{{#if:
|format=
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour October 1990
}}
{{{a}}}|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:

|1980|Dec||{{{4}}} {{#if: |1980|Dec|{{{3}}} {{#if:Dec |1980|Dec {{#if:1980 |1980
         }}
      }}
   }}
}}{{#if:
|format=
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour Dec 1980
}}
{{{a}}}|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:

|1970|August||{{{4}}} {{#if: |1970|August|{{{3}}} {{#if:August |1970|August {{#if:1970 |1970
         }}
      }}
   }}
}}{{#if:
|format=
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour August 1970
}}
{{{{#if:dts|dts| tlf|...}}{{#ifeq:year|year| |year | }}{{#ifeq:month|month| |month | }}{{#ifeq:day|day| |day | }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}}}|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:

|2024|Jun|12|{{{4}}} {{#if:12 |2024|Jun|12 {{#if:Jun |2024|Jun {{#if:2024 |2024
         }}
      }}
   }}
}}{{#if:
|format=
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour Jun 12, 2024
}}
{{{a}}}|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:

|-204|11|22|{{{4}}} {{#if:22 |-204|11|22 {{#if:11 |-204|11 {{#if:-204 |-204
         }}
      }}
   }}
}}{{#if:
|format=
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour November 22, 204 BC
}}
{{{{#if:dts|dts| tlf|...}}{{#ifeq:year|year| |year | }}{{#ifeq:month|month| |month | }}{{#ifeq:day|day| |day | }}{{#ifeq:era|era| |era | }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}}}|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:BC

|44|3|15|BC {{#if:15 |44|3|15 {{#if:3 |44|3 {{#if:44 |44
         }}
      }}
   }}
}}{{#if:
|format=
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour March 15, 44 BC
}}
{{{a}}}|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:AD

|94|Oct|17|AD {{#if:17 |94|Oct|17 {{#if:Oct |94|Oct {{#if:94 |94
         }}
      }}
   }}
}}{{#if:
|format=
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour Oct 17, 94
}}
{{{{#if:dts|dts| tlf|...}}{{#ifeq: }}{{#ifeq:month|month| |month | }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}}}|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:

||May||{{{4}}} {{#if: ||May|{{{3}}} {{#if:May ||May {{#if: |
         }}
      }}
   }}
}}{{#if:
|format=
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour May
}}
{{{{#if:dts|dts| tlf|...}}{{#ifeq: }}{{#ifeq:month|month| |month | }}{{#ifeq:day|day| |day | }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}{{#ifeq:x }}}}|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:

||Sep|12|{{{4}}} {{#if:12 ||Sep|12 {{#if:Sep ||Sep {{#if: |
         }}
      }}
   }}
}}{{#if:
|format=
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour Sep 12
}}

Formatting

Using format produces a format that depends on, but is not necessarily equal to the format of the supplied date. The format parameter can take nine values.

{{#if: | {{#if:| {{#if:| {{#if:dmy| {{#if:| {{#if:dm| {{#if:| {{#if:mdy| {{#if:| {{#if:md| {{#if:| {{#if:my| {{#if:d| {{#if:m| {{#if:y| {{#if:hide|
Examples
value function input code hidden sort key visible output
 |

}}{{#if:format depends on the input|

format depends on the input|

}}|{{dts{{#if:

|26 Jan 1788|||{{{4}}} {{#if: |26 Jan 1788||{{{3}}} {{#if: |26 Jan 1788|{{{2}}} {{#if:26 Jan 1788 |26 Jan 1788
         }}
      }}
   }}
}}{{#if:
|format=
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour 26 Jan 1788
}}
{{{a}}}|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:

|March 12, 1557|||{{{4}}} {{#if: |March 12, 1557||{{{3}}} {{#if: |March 12, 1557|{{{2}}} {{#if:March 12, 1557 |March 12, 1557
         }}
      }}
   }}
}}{{#if:
|format=
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour March 12, 1557
}}
{{{a}}}|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:

|1975-02-13|||{{{4}}} {{#if: |1975-02-13||{{{3}}} {{#if: |1975-02-13|{{{2}}} {{#if:1975-02-13 |1975-02-13
         }}
      }}
   }}
}}{{#if:
|format=
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour February 13, 1975
}}
dmy|

}}{{#if:displays the date in day-month-year format|

displays the date in day-month-year format|

}}|{{dts{{#if:

|Sep 13, 1888|||{{{4}}} {{#if: |Sep 13, 1888||{{{3}}} {{#if: |Sep 13, 1888|{{{2}}} {{#if:Sep 13, 1888 |Sep 13, 1888
         }}
      }}
   }}
}}{{#if:dmy
|format=dmy
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour 13 Sep 1888
}}
{{{a}}}|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:

|1983-01-03|||{{{4}}} {{#if: |1983-01-03||{{{3}}} {{#if: |1983-01-03|{{{2}}} {{#if:1983-01-03 |1983-01-03
         }}
      }}
   }}
}}{{#if:dmy
|format=dmy
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour 3 January 1983
}}
dm|

}}{{#if:displays only the day and month in day-month format|

displays only the day and month in day-month format|

}}|{{dts{{#if:

|Feb 26, 1788|||{{{4}}} {{#if: |Feb 26, 1788||{{{3}}} {{#if: |Feb 26, 1788|{{{2}}} {{#if:Feb 26, 1788 |Feb 26, 1788
         }}
      }}
   }}
}}{{#if:dm
|format=dm
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour 26 Feb
}}
{{{a}}}|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:

|2020-10-15|||{{{4}}} {{#if: |2020-10-15||{{{3}}} {{#if: |2020-10-15|{{{2}}} {{#if:2020-10-15 |2020-10-15
         }}
      }}
   }}
}}{{#if:dm
|format=dm
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour 15 October
}}
mdy|

}}{{#if:displays the date in month-day-year format|

displays the date in month-day-year format|

}}|{{dts{{#if:

|August 31, 1901|||{{{4}}} {{#if: |August 31, 1901||{{{3}}} {{#if: |August 31, 1901|{{{2}}} {{#if:August 31, 1901 |August 31, 1901
         }}
      }}
   }}
}}{{#if:mdy
|format=mdy
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour August 31, 1901
}}
{{{a}}}|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:

|2006-11-08|||{{{4}}} {{#if: |2006-11-08||{{{3}}} {{#if: |2006-11-08|{{{2}}} {{#if:2006-11-08 |2006-11-08
         }}
      }}
   }}
}}{{#if:mdy
|format=mdy
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour November 8, 2006
}}
md|

}}{{#if:displays only the day and month in month-day format|

displays only the day and month in month-day format|

}}|{{dts{{#if:

|26 Jun 1988|||{{{4}}} {{#if: |26 Jun 1988||{{{3}}} {{#if: |26 Jun 1988|{{{2}}} {{#if:26 Jun 1988 |26 Jun 1988
         }}
      }}
   }}
}}{{#if:md
|format=md
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour Jun 26
}}
{{{a}}}|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:

|2002-02-27|||{{{4}}} {{#if: |2002-02-27||{{{3}}} {{#if: |2002-02-27|{{{2}}} {{#if:2002-02-27 |2002-02-27
         }}
      }}
   }}
}}{{#if:md
|format=md
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour February 27
}}
my|

}}{{#if:displays only the month and year in month-year format|

displays only the month and year in month-year format|

}}|{{dts{{#if:

|16 November 1488|||{{{4}}} {{#if: |16 November 1488||{{{3}}} {{#if: |16 November 1488|{{{2}}} {{#if:16 November 1488 |16 November 1488
         }}
      }}
   }}
}}{{#if:my
|format=my
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour November 1488
}}
d|

}}{{#if:displays only the day|

displays only the day|

}}|{{dts{{#if:

|6 July 1666|||{{{4}}} {{#if: |6 July 1666||{{{3}}} {{#if: |6 July 1666|{{{2}}} {{#if:6 July 1666 |6 July 1666
         }}
      }}
   }}
}}{{#if:d
|format=d
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour 6
}}
m|

}}{{#if:displays only the month|

displays only the month|

}}|{{dts{{#if:

|1980-02-12|||{{{4}}} {{#if: |1980-02-12||{{{3}}} {{#if: |1980-02-12|{{{2}}} {{#if:1980-02-12 |1980-02-12
         }}
      }}
   }}
}}{{#if:m
|format=m
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour February
}}
y|

}}{{#if:displays only the year|

displays only the year|

}}|{{dts{{#if:

|-26|Jan|18|{{{4}}} {{#if:18 |-26|Jan|18 {{#if:Jan |-26|Jan {{#if:-26 |-26
         }}
      }}
   }}
}}{{#if:y
|format=y
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour 26 BC
}}
hide|

}}{{#if:hides the date|

hides the date|

}}|{{dts{{#if:

|15 October 1800|||{{{4}}} {{#if: |15 October 1800||{{{3}}} {{#if: |15 October 1800|{{{2}}} {{#if:15 October 1800 |15 October 1800
         }}
      }}
   }}
}}{{#if:hide
|format=hide
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour
}}

Abbreviation

There are two ways of abbreviating the month name.

  1. Directly input an abbreviated month name.
  2. Use the abbr=on parameter.
{{#if:none| {{#if:| {{#if:| {{#if:| {{#if:abbreviated input| {{#if:| {{#if:abbr=on| {{#if:| {{#if:| {{#if:|
Examples
abbreviation method input code hidden sort key visible output
none|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:

|2000-01-01|||{{{4}}} {{#if: |2000-01-01||{{{3}}} {{#if: |2000-01-01|{{{2}}} {{#if:2000-01-01 |2000-01-01
         }}
      }}
   }}
}}{{#if:
|format=
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour January 1, 2000
}}
{{{a}}}|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:

|2000|1|1|{{{4}}} {{#if:1 |2000|1|1 {{#if:1 |2000|1 {{#if:2000 |2000
         }}
      }}
   }}
}}{{#if:
|format=
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour January 1, 2000
}}
{{{a}}}|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:

|1 January 2000|||{{{4}}} {{#if: |1 January 2000||{{{3}}} {{#if: |1 January 2000|{{{2}}} {{#if:1 January 2000 |1 January 2000
         }}
      }}
   }}
}}{{#if:
|format=
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour 1 January 2000
}}
{{{a}}}|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:

|2000|January|1|{{{4}}} {{#if:1 |2000|January|1 {{#if:January |2000|January {{#if:2000 |2000
         }}
      }}
   }}
}}{{#if:
|format=
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour January 1, 2000
}}
abbreviated input|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:

|1 Jan 2000|||{{{4}}} {{#if: |1 Jan 2000||{{{3}}} {{#if: |1 Jan 2000|{{{2}}} {{#if:1 Jan 2000 |1 Jan 2000
         }}
      }}
   }}
}}{{#if:
|format=
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour 1 Jan 2000
}}
{{{a}}}|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:

|2000|Jan|1|{{{4}}} {{#if:1 |2000|Jan|1 {{#if:Jan |2000|Jan {{#if:2000 |2000
         }}
      }}
   }}
}}{{#if:
|format=
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour Jan 1, 2000
}}
abbr=on|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:

|1 January 2000|||{{{4}}} {{#if: |1 January 2000||{{{3}}} {{#if: |1 January 2000|{{{2}}} {{#if:1 January 2000 |1 January 2000
         }}
      }}
   }}
}}{{#if:
|format=
}}{{#if:on
|abbr=on
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour 1 Jan 2000
}}
{{{a}}}|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:

|2000|January|1|{{{4}}} {{#if:1 |2000|January|1 {{#if:January |2000|January {{#if:2000 |2000
         }}
      }}
   }}
}}{{#if:
|format=
}}{{#if:on
|abbr=on
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour Jan 1, 2000
}}
{{{a}}}|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:

|2000-01-01|||{{{4}}} {{#if: |2000-01-01||{{{3}}} {{#if: |2000-01-01|{{{2}}} {{#if:2000-01-01 |2000-01-01
         }}
      }}
   }}
}}{{#if:
|format=
}}{{#if:on
|abbr=on
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour Jan 1, 2000
}}
{{{a}}}|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:

|2000|1|1|{{{4}}} {{#if:1 |2000|1|1 {{#if:1 |2000|1 {{#if:2000 |2000
         }}
      }}
   }}
}}{{#if:
|format=
}}{{#if:on
|abbr=on
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour Jan 1, 2000
}}

Additional sort key

In case two dates in a table are identical they may be ordered using the addkey parameter.

{{#if:| {{#if:| {{#if:| {{#if:| {{#if:| {{#if:| {{#if:|
Examples
input code hidden sort key visible output
{{{a}}}|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:

|2010-10-10|||{{{4}}} {{#if: |2010-10-10||{{{3}}} {{#if: |2010-10-10|{{{2}}} {{#if:2010-10-10 |2010-10-10
         }}
      }}
   }}
}}{{#if:
|format=
}}{{#if:
|abbr=
}}{{#if:3
|addkey=3
}}}}

{{#if:

Template:Dts/testcases/colour October 10, 2010
}}
{{{a}}}|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:

|2010-10-09|||{{{4}}} {{#if: |2010-10-09||{{{3}}} {{#if: |2010-10-09|{{{2}}} {{#if:2010-10-09 |2010-10-09
         }}
      }}
   }}
}}{{#if:
|format=
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour October 9, 2010
}}
{{{a}}}|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:

|2010-10-10|||{{{4}}} {{#if: |2010-10-10||{{{3}}} {{#if: |2010-10-10|{{{2}}} {{#if:2010-10-10 |2010-10-10
         }}
      }}
   }}
}}{{#if:
|format=
}}{{#if:
|abbr=
}}{{#if:1
|addkey=1
}}}}

{{#if:

Template:Dts/testcases/colour October 10, 2010
}}
{{{a}}}|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:

|2010-10-10|||{{{4}}} {{#if: |2010-10-10||{{{3}}} {{#if: |2010-10-10|{{{2}}} {{#if:2010-10-10 |2010-10-10
         }}
      }}
   }}
}}{{#if:
|format=
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour October 10, 2010
}}
{{{a}}}|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:

|2010-10-10|||{{{4}}} {{#if: |2010-10-10||{{{3}}} {{#if: |2010-10-10|{{{2}}} {{#if:2010-10-10 |2010-10-10
         }}
      }}
   }}
}}{{#if:
|format=
}}{{#if:
|abbr=
}}{{#if:4
|addkey=4
}}}}

{{#if:

Template:Dts/testcases/colour October 10, 2010
}}
{{{a}}}|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:

|2010-10-11|||{{{4}}} {{#if: |2010-10-11||{{{3}}} {{#if: |2010-10-11|{{{2}}} {{#if:2010-10-11 |2010-10-11
         }}
      }}
   }}
}}{{#if:
|format=
}}{{#if:
|abbr=
}}{{#if:
|addkey=
}}}}

{{#if:

Template:Dts/testcases/colour October 11, 2010
}}
{{{a}}}|

}}{{#if:|

{{{b}}}|

}}|{{dts{{#if:

|2010-10-10|||{{{4}}} {{#if: |2010-10-10||{{{3}}} {{#if: |2010-10-10|{{{2}}} {{#if:2010-10-10 |2010-10-10
         }}
      }}
   }}
}}{{#if:
|format=
}}{{#if:
|abbr=
}}{{#if:2
|addkey=2
}}}}

{{#if:

Template:Dts/testcases/colour October 10, 2010
}}

Wrapping

To turn off the suppression of word wraps, use the nowrap=off parameter.

Notes

Sorting for incomplete dates

Whole months or years
A whole year or month (and year) is sorted according to its first day.
Missing years
If the year is not specified, the date will be sorted as if the year were the current year.
Blank dates
For no date input at all, the maximum possible sort key is used, so the entry will sort last.

Error handling

Entering an invalid date format will (generally) produce an error message such as the one below.

Error in Template:Dts: days must be an integer between 1 and 31

Errors are tracked in Category:Dts templates with errors.

Calendar choice

The template is not capable of distinguishing Julian and Gregorian calendar dates. Also, it is not capable of taking a date in one calendar as input and outputting a date in the other calendar. Thus, to insure proper sorting, editors must either use one calendar for all dates, or pick a specific changeover date (for example, deciding that 4 October 1582 is Julian and all later dates are Gregorian); this would be done on an article-by article basis. Editors are also responsible for explaining to the reader whether the visible dates are Julian or Gregorian, if there is any possibility of confusion.

Linking

The template formerly linked dates automatically, with link=off used to suppress linking. In accordance with current guidelines linking of dates is no longer supported and instances of link=off should be removed. Transclusions using the |{{#if:link|link=}} parameter are tracked in Category:Dts templates with deprecated parameters.

See also

|(backlinks edit) |90% }}, since on Meta e.g. 09999 9999 induces numeric sort mode, "&" is prefixed to force string sort mode.

  • {{sort}}, sorting by a specified key (also good for complicated numbers, e.g. scientific notation)
  • {{sortname}}, full name sorting (using "last name, first name" as default sort key)
  • {{tts}}, for sorting times in result tables of athletic events (only needed in certain cases - see template documentation)
  • {{mss}}, for sorting times in tables of eclipses
  • {{nts}}, for numbers

{{#ifeq:Dts|sandbox | |

}}