This is not a Wikipedia article: It is an individual user's work-in-progress page, and may be incomplete and/or unreliable. The current/final version of this article may be located at Help:Date formatting and linking now or in the future. For guidance on developing this draft, see Wikipedia:So you made a userspace draft. Find sources: Google (books · news · scholar · free images · WP refs) · FENS · JSTOR · TWL |
- Note that the linking of dates in Wikipedia articles is discouraged in most cases. For guidance, see WP:Linking#Chronological items.
The date formatting feature (autoformatting of dates), automatically reformats linked dates, at least when they are typed in certain formats.
This feature is enabled when $wgUseDynamicDates is set to true.
If this feature is enabled, the reformatted link target is constant, but the reformatted appearance depends on the user's preference setting for the date format. This preference setting also affects dates and times produced by the system in Recent Changes etc.
Visual summary
editThe following is rendered depending on preferences
syntax | wikitext | result | month/day target |
---|---|---|---|
ISO1 | [[2001]]-[[01-05]] | 2001-01-05 | January 5 |
ISO2 | [[2001-01-05]] | 2001-01-05 | January 5 |
YMD | [[2001]] [[January 5]] | 2001 January 5 | January 5 |
YMD | [[2001]] [[January 05]] | 2001 January 05 | January 05 |
YMD | [[2001]] [[Jan 5]] | 2001 Jan 5 | Jan 5 |
YMD | [[2001]] [[Jan 05]] | 2001 Jan 05 | Jan 05 |
YDM | [[2001]] [[5 January]] | 2001 5 January | January 5 |
YDM | [[2001]] [[05 January]] | 2001 05 January | January 05 |
YDM | [[2001]] [[5 Jan]] | 2001 5 Jan | Jan 5 |
YDM | [[2001]] [[05 Jan]] | 2001 05 Jan | Jan 05 |
MDY | [[January 5]] [[2001]] | January 5 2001 | January 5 |
MDY | [[January 05]] [[2001]] | January 05 2001 | January 05 |
MDY | [[Jan 5]] [[2001]] | Jan 5 2001 | Jan 5 |
MDY | [[Jan 05]] [[2001]] | Jan 05 2001 | Jan 05 |
DMY | [[5 January]] [[2001]] | 5 January 2001 | January 5 |
DMY | [[05 January]] [[2001]] | 05 January 2001 | January 05 |
DMY | [[5 Jan]] [[2001]] | 5 Jan 2001 | Jan 5 |
DMY | [[05 Jan]] [[2001]] | 05 Jan 2001 | Jan 05 |
format | wikicode | result | month/day target |
---|---|---|---|
MD | [[January 5]] | January 5 | January 5 |
MD | [[January 05]] | January 05 | January 05 |
MD | [[Jan 5]] | Jan 5 | Jan 5 |
MD | [[Jan 05]] | Jan 05 | Jan 05 |
DM | [[5 January]] | 5 January | January 5 |
DM | [[05 January]] | 05 January | January 05 |
DM | [[5 Jan]] | 5 Jan | Jan 5 |
DM | [[05 Jan]] | 05 Jan | Jan 05 |
In the file includes/parser/DateFormatter.php (r55433) the different syntaxes are handled by Perl-Compatible Regular Expressions (PCRE). If you have the ability to understand these, the following code block may be very explanatory, the rest of the document is spent explaining it:
$this->regexTrail = '(?![a-z])/iu'; # Partial regular expressions $this->prxDM = '\[\[(\d{1,2})[ _](' . $this->monthNames . ')\]\]'; $this->prxMD = '\[\[(' . $this->monthNames . ')[ _](\d{1,2})\]\]'; $this->prxY = '\[\[(\d{1,4}([ _]BC|))\]\]'; $this->prxISO1 = '\[\[(-?\d{4})]]-\[\[(\d{2})-(\d{2})\]\]'; $this->prxISO2 = '\[\[(-?\d{4})-(\d{2})-(\d{2})\]\]'; # Real regular expressions $this->regexes[self::DMY] = "/{$this->prxDM}(?: *, *| +){$this->prxY}{$this->regexTrail}"; $this->regexes[self::YDM] = "/{$this->prxY}(?: *, *| +){$this->prxDM}{$this->regexTrail}"; $this->regexes[self::MDY] = "/{$this->prxMD}(?: *, *| +){$this->prxY}{$this->regexTrail}"; $this->regexes[self::YMD] = "/{$this->prxY}(?: *, *| +){$this->prxMD}{$this->regexTrail}"; $this->regexes[self::DM] = "/{$this->prxDM}{$this->regexTrail}"; $this->regexes[self::MD] = "/{$this->prxMD}{$this->regexTrail}"; $this->regexes[self::ISO1] = "/{$this->prxISO1}{$this->regexTrail}"; $this->regexes[self::ISO2] = "/{$this->prxISO2}{$this->regexTrail}";
Syntax
editThere are several different syntaxes that this feature will accept. All of these have several things in common:
- They are insensitive to whether a letter is uppercase or lowercase
- They may not be immediatly followed by a letter "a-z"[1] (also not cap-sensitive)
ISO1 / ISO2
editsyntax | wikitext | result | month/day target |
---|---|---|---|
ISO1 | [[2001]]-[[01-05]] | 2001-01-05 | January 5 |
ISO2 | [[2001-01-05]] | 2001-01-05 | January 5 |
- The year must be exactly 4 digits.[2] It may be preceded by a "-" to identify it as BC / BCE.
- The month must be exactly 2 digits.
- The day must be exactly 2 digits.
MD / DM
editformat | wikicode | result | month/day target |
---|---|---|---|
MD | [[January 5]] | January 5 | January 5 |
MD | [[January 05]] | January 05 | January 05 |
MD | [[Jan 5]] | Jan 5 | Jan 5 |
MD | [[Jan 05]] | Jan 05 | Jan 05 |
DM | [[5 January]] | 5 January | January 5 |
DM | [[05 January]] | 05 January | January 05 |
DM | [[5 Jan]] | 5 Jan | Jan 5 |
DM | [[05 Jan]] | 05 Jan | Jan 05 |
DMY / YDM / MDY / YMD
editsyntax | wikitext | result | month/day target |
---|---|---|---|
YMD | [[2001]] [[January 5]] | 2001 January 5 | January 5 |
YMD | [[2001]] [[January 05]] | 2001 January 05 | January 05 |
YMD | [[2001]] [[Jan 5]] | 2001 Jan 5 | Jan 5 |
YMD | [[2001]] [[Jan 05]] | 2001 Jan 05 | Jan 05 |
YDM | [[2001]] [[5 January]] | 2001 5 January | January 5 |
YDM | [[2001]] [[05 January]] | 2001 05 January | January 05 |
YDM | [[2001]] [[5 Jan]] | 2001 5 Jan | Jan 5 |
YDM | [[2001]] [[05 Jan]] | 2001 05 Jan | Jan 05 |
MDY | [[January 5]] [[2001]] | January 5 2001 | January 5 |
MDY | [[January 05]] [[2001]] | January 05 2001 | January 05 |
MDY | [[Jan 5]] [[2001]] | Jan 5 2001 | Jan 5 |
MDY | [[Jan 05]] [[2001]] | Jan 05 2001 | Jan 05 |
DMY | [[5 January]] [[2001]] | 5 January 2001 | January 5 |
DMY | [[05 January]] [[2001]] | 05 January 2001 | January 05 |
DMY | [[5 Jan]] [[2001]] | 5 Jan 2001 | Jan 5 |
DMY | [[05 Jan]] [[2001]] | 05 Jan 2001 | Jan 05 |
Link targets
editThe link targets (the pages that are linked to) are independent of the user-specified date format.
Year
editThe year has no leading zeros, e.g. "2007", "7", "7 BC".
Month/Day
editFor the date 5 January 2001, apart from the year ("2001"), there are 4 possible link targets, depending on the wikitext. They are
- January 5
- January 05
- Jan 5
- Jan 05
[[2001]]-[[01-05]] produces links to "2001" and "January 5". Although [[2001-01-05]] has the form of a single link, it produces the same two links.
Unlinked date
editIf the date needs not be linked, and the links that have to be created for autoformatting are even undesirable (because they clutter the page, or invite to create unneeded pages) the date cannot be autoformatted. See also the extension mentioned below to allow autoformatting anyway.
Link to date content other than required for autoformatting
editIf the links that have to be created for autoformatting do not include those with the desired target(s), we can choose between:
- using a fixed date format (so the user-preferences do not apply), and provide a link as desired
- apply autoformatting, but add the desired link at the end
Whether to link to a year page, a month page, or a day page, depends on factors such as whether a year page would get too large to hold all content about the year; if so, both a link to a summary year page and a detailed month page could be useful. Either way, it would be useful to link to the section concerned.
From some sites other than Wikipedia, if we want to link to general content about a year, month or day, we may want to link to Wikipedia instead of to an internal page.
Linking a date to date content is not only useful for accessing that content, but also for the backlink: to find pages linking to a particular year, month or day. This gives us a list of events (and subjects related to events) that happened in (or are at least related to) that time period. This also allows easy checking of completeness and consistency of the source and target page.
Examples of links:
- 5 March 2007 (5 March 2007)
- 5 March 2007 (5 March 2007)
- 5 March 2007 [1] (linking to the separate page about this date); backlinks of this type: [2]
- 5 March 2007 [3] (linking to the section of the month page); backlinks of this type: [4]
The day number in the anchor in w:Portal:Current events/DateHeader2, when below 10, has a leading zero. This avoids that asking for backlinks of 1 March also gives pages linking to 10 March etc.
In the case of linking to a separate page about a date this would require the leading zero in the page title, unless even in a link to such a page, we link to the anchor. For example, link 10 March 2007 [5] causes a false result when we ask for backlinks of 1 March: [6]. On the other hand, link 10 March 2007 [7] causes no false result when we ask for backlinks of 1 March: [8]
Usage of the links
editIf we do use the date formatting feature we get links to e.g. "2007", "7", "7 BC", so it is practical to use these pagenames, not e.g. "Year 2007", "0007", or "7 B.C.". If not we can create a redirect.
Also we get a link to "January 5", "January 05", "Jan 5", or "Jan 05", so if we want to create pages on days of the year it is practical to choose one of these four pagename formats, and not e.g. "5 January". Again, if such names are not desired we can use redirects. Also, if the content concerned is in a section of a page we can redirect to that section.
Anyway, links like and can be used even if the link targets do not exist.
Appearances
editOption "default": the appearance is as without the date formatting feature, except:
- the wikitext [[2001-01-05]] gives the same appearance as [[2001]]-[[01-05]]
- if the day is in the center, a comma is put at the year side, if it is not there yet
- if the day is not in the center, a possible comma is removed
Option "MDY ": format [[m d]], [[y]] or [[m d]]
Option "DMY ": format [[m d|d m]] [[y]] or [[m d|d m]]
Option "YMD ": format [[y]] [[m d]] or [[m d]]
Option "ISO 8601":
- format [[y]]-[[m-d]] with numeric m, and m and d with leading zeros.
- without year: appearance as without the date formatting feature
Years before 1000
editFor years in the range 1-999, in the case of month numbers the year has to be padded with zeros; the link target for the year has to leading zeros: *month/day link target "Januari 5": **[[0011-01-05]] or [[0011]]-[[01-05]] **[[11]][[january 5]] **[[11]][[5 january]] **[[january 5]][[11]] **[[5 january]][[11]] ||
With your current preference setting on this project this gives:
- month/day link target "Januari 5":
For years B.C. we get link targets of the form "12 BC":
*month/day link target "Januari 5": **[[-0011-01-05]] or [[-0011]]-[[01-05]] **[[12 BC]][[january 5]] **[[12 BC]][[5 january]] **[[january 5]][[12 BC]] **[[5 january]][[12 BC]] ||
With your current preference setting on this project this gives:
User-dependent section title
editIf a section title contains a link in a format such that the date formatting feature applies, the section title is user-dependent. However, for section linking this would require a link target that is correspondingly user-dependent, which does not seem possible with the current software without some special extension. Therefore it is better not to use a real section but a special-font header in user-dependent format with an explicitly defined anchor in a fixed date format, see w:Portal:Current events/DateHeader2 (talk). One can use e.g. Template:datelink (backlinks edit) to link to it.
Sorting
editFor chronological table sorting the format [[YYYY-MM-DD]] works directly; in other cases date sorting only works if a table has been specially adapted for that purpose. An additional effect of selecting this preference is that Recent Changes, User Contributions, etc., also gives seconds: "HH:mm:SS", or with the date: "YYYY-MM-DDTHH:mm:SS".
Wikitext for which the date formatting feature does not apply
editWith a piped link the date formatting feature is disabled. In particular this can be used to link to "5 January", etc.
*Piped link: **[[5 January|]] [[2001]] *Numeric date format without leading zeros: **[[2001-1-5]] **[[2001]]-[[1-5]] *Numeric date format without year: **[[01-05]] *Non-standard month name: **[[2001]] [[Janu 5]] **[[2001]] [[Janu 05]] **[[Janu 5]], [[2001]] **[[Janu 05]], [[2001]] **[[Janu 5]] [[2001]] **[[Janu 05]] [[2001]] **[[5 Janu]] [[2001]] **[[05 Janu]] [[2001]] **[[Janu 5]] **[[Janu 05]] **[[5 Janu]] **[[05 Janu]] ||
gives:
- Piped link:
- Numeric date format without leading zeros:
- Numeric date format without year:
- Non-standard month name:
Unfortunately, when linking to content about a specific date (with a separate page, a section of a page, or another anchor) the date formatting feature cannot be used for the link label, so the label is fixed, not user-dependent.
When linking to another site (with an interwiki link or external link) the label cannot be user-dependent either.
Example:
- [[w:Portal:Current events/2007 March 5|5 March 2007]] gives 5 March 2007.
When pages describing events link like this to the dates they happened or will happen (with internal links, not interwiki links) we can find the events on a given date with e.g. w:Special:Whatlinkshere/Portal:Current_events/2007 March 5.
Date range
editAttempts:
- 14–26 November 2006
- November 14–26 2006
- November 14–November 26 2006
- 14 November–26 November 2006
- 14 November 2006–26 November 2006
Only the last, cumbersome, way does not give strange results in any user-specified date format. Since the date-formatting feature does not work well here one may choose not to use it in this case; that also gives the freedom to choose link targets exactly as desired, e.g.:
- [[w:Portal:Current events/2006 November 14|14]]–[[w:Portal:Current events/2006 November 26|26 November 2006]] giving 14–26 November 2006
or
- [[w:November 2006#2006 November 14|14–26 November 2006]] giving 14–26 November 2006.
See also date ranges (discussion).
See also
edit- Date preferences screenshot
- m:Dynamic dates
- w:en:Wikipedia:Manual of Style (dates and numbers)#Dates (talk)
- w:Wikipedia:Date debate
- bugzilla:4582 - Use date format preference on unlinked dates
- FormatDates extension - tags <date>..</date> for autoformatting dates without producing links (and, presumably, to allow an autoformatted date as link label in a link with a target of choice)
- DateParser