Template:Extract/doc

'''This template can extract information from a date, or can format a date. Time units can be added to a date.'''

Syntax


The following options are available:
 * • Add/subtract time units.
 * • Adjust invalid time units.
 * • Accept a year only, or a year and month only.
 * • Specifies what should be extracted (such as ), or how to format the date (such as  ).
 * • A hidden sort key is inserted before the date (for use in sortable tables).

The date can be entered as the first parameter, or separate parameters can be used for the year/month/day/hour/minute/second components of a date.

By default, the date is displayed in dmy format, for example:

Date
A valid date must be specified. Dates are UTC—local times and time zones are not supported.

Dates from 9999 BCE to 9999 CE are accepted. The proleptic Gregorian calendar is used by default. Entering the parameter  with a date uses the proleptic Julian calendar.

A date can include an era or a time, and a variety of formats are accepted.

Examples of valid dates follow. Each row shows two equivalent methods of entering a date.

The last example above uses the rule:
 * n BC is year 1 − n

Year 0 refers to 1 BC, and year −1 is 2 BC, etc.

Dates can also be entered with the following special names which are not case sensitive.

The following confirms that 16 February 2000 in the Julian calendar was 29 February 2000 in the Gregorian calendar.

16 February 2000 in the Julian calendar can be converted to the Gregorian calendar in one line:

Add
These time units can be added to a date:
 * years
 * months
 * days
 * hours
 * minutes
 * seconds

Multiple periods can be given, separated by spaces. There must be no space between a value and the code for the time unit.

A hyphen can be used for a negative value. Periods are added in the order given.

Examples:

Fix
By default, the date entered must be valid. If  is used, units which are too large are "fixed". For example, 26 hours would be regarded as 1 day and 2 hours.

Entering a day as zero is regarded as the previous day (the last day of the previous month). The day before the previous day would be indicated with.

Similarly, entering a month as zero goes back one month, and entering  goes back two months.

Examples:

The following shows how to get the date for a given year and day-of-year. For example, June 30, 2001 is day 181 in the year 2001, as can be seen by adding 181 days to the date just before January 1, 2001.

Partial
If  is used, the date may consist of a year only, or a year and month only. Addition is not supported for a partial date.

Show
The following table lists most of the show parameters that can be used. Some of these work properly only with a full date.

Examples:

Some  options will not produce a useful result with a partial date, for example:

Sortable
The sort options are:

The sort key is calculated from the  value. For a partial date such as May 2016, the first day in the range is used (1 May 2016).

If wanted,  can be used so the date is not displayed.

The  parameter allows the insertion of text that will not interfere with sorting. For example,  outputs a hidden sort key followed by "c. 500 BC".

Examples: