Bản mẫu: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=periods to add • Add/subtract time units.
*fix=on • Adjust invalid time units.
*partial=on • Accept a year only, or a year and month only.
*show=what to display • Specifies what should be extracted (such as dayname), or how to format the date (such as mdy).
*sortable=on • 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:- → 2015-11-12

**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 julian 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.- → 2451545 green|1=(Julian day 2451545 is noon 1 January 2000 UTC in the Gregorian calendar)- → 2451545 1=(which is 19 December 1999 in the Julian calendar)- → currentdate green|1=(the date shown is when this documentation page was last purged)- → currentdatetime
The following confirms that 16 February 2000 in the Julian calendar was 29 February 2000 in the Gregorian calendar.- → show=juliandate 1=(Julian calendar was specified)- → 2451604 1=(Gregorian calendar by default)
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:
*y years
*m months
*d days
*h hours
*min minutes
*s 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:- → add=28d- → add=3m 28d- → add=28d 3m 1=(the order in which units are added changes the result)- → add=-3d- → add=-912345d- → add=250h- → add=-2.5h- → add=-2m- → add=2y 3m 4d- → add=5.75d 1=(years and months are integer only)

**Fix**
By default, the date entered must be valid. If fix=on 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 -1.
Similarly, entering a month as zero goes back one month, and entering -1 goes back two months.
Examples:- → fix=on 1=(no fix is required)- → fix=on- → fix=on- → fix=on- → fix=on- → fix=on
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.- → show=dayofyear 1=(date to day-of-year)- → show=mdy 1=(day-of-year to date)

**Partial**
If partial=on is used, the date may consist of a year only, or a year and month only. Addition is not supported for a partial date.- → partial=on- → show=isleapyear

**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:- → 1 Feb 2001- → FEB 1 2001- → 2001-2-1- → show=format- → show=format- → show=format- → show=format- → show=mdy- → show=ymd- → show=dayname- → show=dayofyear- → show=monthname- → 
Some show options will not produce a useful result with a partial date, for example:- → show=juliandate- → show=monthname

**Sortable**
The sort options are:
The sort key is calculated from the juliandate value. For a partial date such as May 2016, the first day in the range is used (1 May 2016).
If wanted, show=hide can be used so the date is not displayed.
The prefix 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:- → sortable=on- → show=hide- → sortable=debug- → sortable=debug- → show=hide- → show=hide